[fpc-pascal] Strings
Carsten Bager
carsten at beas.dk
Tue Jul 16 12:17:43 CEST 2013
Hi
I have a question about dynamic strings and memory allocation.
If you look at my example underneath, I depend on that a dynamic string always is assigned
memory space in one connected block. But will that always be the case in various operating
systems.
Carsten
Function Sum(p:pointer; len:LongInt):LongInt;
Type
a_typ=array[0..pred(maxLongInt)] of byte;
a=^a_typ;
var
i:LongInt;
Begin
result:=0;
for i:=0 to len do
result:=result+a(p)^[i];
End;
Procedure test;
Var
s:ansistring;
i:integer;
Begin
s:='Something';
for i:=0 to 100000 do
s:=s+'Test';
if Sum(@s[1],length(s)) = 0 then
halt(0);
End;
Med venlig hilsen
Carsten Bager
BEAS A/S
Brørupvænget 10
DK-7650 Bøvlingbjerg
Tlf. : +45 9788 5222 Fax : +45 9788 5434
www.beas.dk
More information about the fpc-pascal
mailing list