Wednesday 23 December 2009

Unicode technical paper from Cary Jensen

Cary Jensen has produced a White Paper about migrating to Delphi 2009, with real stories from real migrations. View it here or download it here. The paper is the result of his call for migration stories, earlier, and a lot of people contributed with examples, including me. Besides being a good paper to read before migrating, it also explains many things that most may not be aware of.

6 comments:

Anonymous said...

"StringElementSize(Buffer)" holy sh**.
I hope Cary knows what he is doing on page 22. Creating two temporary unicode strings from Buffer (because StringElementSize is inlined) will give you a really heavy performance hit.

Why don't I see a SizeOf(Char) anywhere in his paper. StringElementSize() is for the C++Builder UnicodeString disaster not for general usage.

Lars D said...

I don't see where the performance problem is - StringElementSize(stringtype) compiles into a constant in machine code, in Delphi.

Anonymous said...

The problem is that "Buffer" is not a string-type on page 22. It is an array[] of Char. And because that array-type is assign compatible to UnicodeString (Compiler Magic makes it possible) the compiler generates a call to UStrFromWCharArray. And because StringElementSize is inlined the it adds two calls, what requires a hidden try/finally and two temporary string variables.

Lars D said...

Good point - I can verify that. I guess someone should tell Olaf :-)

Cary Jensen said...

Thank you for posting these comments. There are several errors that have been pointed out now that the article has been published, and I will get them taken care of, but it might take a week or two due to the holidays.

Also, it's not Olaf's error, it's mine. This was a big paper (15,000 words), and I welcome the opportunity to make additional corrections, and even add additional material in a future release.

Cary Jensen said...

The issue that ahuser brings up was addressed, as well as another issue that another reader reported. The updated white paper has now been posted. You can find it at http://embarcadero.com/images/dm/technical-papers/delphi-unicode-migration.pdf