[fpc-devel] Performance of string handling in trunk
Sven Barth
pascaldragon at googlemail.com
Wed Jun 26 12:13:47 CEST 2013
Am 26.06.2013 09:41, schrieb Michael Schnell:
> On 06/25/2013 01:20 PM, Hans-Peter Diettrich wrote:
>> Michael Schnell schrieb:
>>> Supposedly the length and encoding number and code-bytecount is
>>> copied, too.
>>
>> Please understand reference counted memory objects :-]
> Please check this program I tested with a pre-Unicode Delphi.
>
> It shows that (of course) the string length gets copied when assigning
> a string variable to another and how it is done.
>
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:
=== code begin ===
program tstrassign;
{$apptype console}
{$ifdef fpc}
{$H+}
{$endif}
{$ifndef fpc}
uses
SysUtils;
function hexstr(ptr: Pointer): String;
begin
Result := IntToHex(Integer(ptr), 8);
end;
{$endif}
var
s1, s2: String;
begin
s1 := 'Test';
Writeln(hexstr(Pointer(s1)), ' ', hexstr(Pointer(s2)));
s2 := s1;
Writeln(hexstr(Pointer(s1)), ' ', hexstr(Pointer(s2)));
end.
=== code end ===
Regards,
Sven
More information about the fpc-devel
mailing list