[fpc-devel] Performance of string handling in trunk

Michael Schnell mschnell at lumino.de
Wed Jun 26 12:38:44 CEST 2013


On 06/26/2013 12:13 PM, Sven Barth wrote:
> You do know that s2 will point to the same record of s1 after the 
> assignment? The contents of the string record are not copied, only the 
> pointer of s2 will change. See this example:
>

You are right (my testing program in pre-Unicode-Delphi does show 
exactly this).

But what I wanted to show is, that here more is done but just managing 
the reference count. Regarding the dispute I had with dodi, he thus is 
right that the length is not exactly _copied_over_, but the pointer is 
managed in a way that the same length (and content) is shown. (I admit 
that he is correct calling this just "reference counting".)

Regarding the underlying discussion about RawByteString:
If exactly this is done when assigning a normal String variable to a 
RawByteString Variable, it happens exactly what I suppose (and dodi 
seems to deny): the dynamic encoding type of the RawByteString (target) 
will be set to the encoding type of the normal String (source). Thus the 
encoding type is _not_ lost and (in principle) when assigning a 
RawByteString to a normal String, the library would be able to check the 
actual dynamic encoding type of the source against the (static=dynamic) 
encoding type of the target and do a conversion if appropriate. IMHO 
this would be a very sensible behavior.

-Michael



More information about the fpc-devel mailing list