[fpc-pascal] Strings

Jeppe Græsdal Johansen jeppe at j-software.dk
Tue Jul 16 13:45:11 CEST 2013


Why not just skip all the encoding uncertainity of strings and use an 
array of byte/char?

It'll probably be a lot faster too

Den 16-07-2013 12:17, Carsten Bager skrev:
> 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
>
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>




More information about the fpc-pascal mailing list