[fpc-devel] Performance of string handling in trunk
Michael Schnell
mschnell at lumino.de
Wed Jun 26 09:41:27 CEST 2013
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.
-Michael
===========================================================================0
var
s1, s2: String;
i1, i2: Integer;
j1, j2: Integer;
l1, l2: Integer;
p1, p2: PChar;
x1, x2: PInteger;
y1, y2: PInteger;
z1, z2: PInteger;
procedure TForm12.FormCreate(Sender: TObject);
begin
s1 := 'ABCDEFG';
l1 := Length(s1);
l2 := Length(s2);
p1 := pchar(s1);
p2 := pchar(s2);
i1 := Integer(@s1);
i2 := Integer(@s2);
j1 := Integer(p1);
j2 := Integer(p2);
x1 := PInteger(j1);
x2 := PInteger(j2);
y1 := PInteger(j1-4);
y2 := PInteger(j2-4);
z1 := PInteger(j1-8);
z2 := PInteger(j2-8);
Memo1.Lines.Add('l : ' + IntToStr(l1) + ' ' + IntToStr(l2));
Memo1.Lines.Add('i : ' + IntToHex(i1, 8) + ' ' + IntToHex(i2, 8) + '
(@s)');
Memo1.Lines.Add('j : ' + IntToHex(j1, 8) + ' ' + IntToHex(j2, 8) + '
(s = String Record)');
Memo1.Lines.Add('x^: ' + IntToHex(x1^, 8) + ' ' + IntToHex(x2^, 8) + '
(^s-0 = Content)');
Memo1.Lines.Add('y^: ' + IntToHex(y1^, 8) + ' ' + IntToHex(y2^, 8) + '
(^s-4 = Length)');
Memo1.Lines.Add('z^: ' + IntToHex(z1^, 8) + ' ' + IntToHex(z2^, 8) + '
(^s-8)= RefCount');
s2 := s1;
Memo1.Lines.Add('====================');
l1 := Length(s1);
l2 := Length(s2);
p1 := pchar(s1);
p2 := pchar(s2);
i1 := Integer(@s1);
i2 := Integer(@s2);
j1 := Integer(p1);
j2 := Integer(p2);
x1 := PInteger(j1);
x2 := PInteger(j2);
y1 := PInteger(j1-4);
y2 := PInteger(j2-4);
z1 := PInteger(j1-8);
z2 := PInteger(j2-8);
Memo1.Lines.Add('l : ' + IntToStr(l1) + ' ' + IntToStr(l2));
Memo1.Lines.Add('i : ' + IntToHex(i1, 8) + ' ' + IntToHex(i2, 8) + '
(@s)');
Memo1.Lines.Add('j : ' + IntToHex(j1, 8) + ' ' + IntToHex(j2, 8) + '
(s = String Record)');
Memo1.Lines.Add('x^: ' + IntToHex(x1^, 8) + ' ' + IntToHex(x2^, 8) + '
(^s-0 = Content)');
Memo1.Lines.Add('y^: ' + IntToHex(y1^, 8) + ' ' + IntToHex(y2^, 8) + '
(^s-4 = Length)');
Memo1.Lines.Add('z^: ' + IntToHex(z1^, 8) + ' ' + IntToHex(z2^, 8) + '
(^s-8)= RefCount');
end;
More information about the fpc-devel
mailing list