[fpc-pascal] string concatenation speed
Marc Santhoff
M.Santhoff at t-online.de
Tue Jun 21 20:36:38 CEST 2005
Am Dienstag, den 21.06.2005, 19:21 +0200 schrieb Marco van de Voort:
> > in an application of mine occurs a lot of string separation and
> > re-concatenation. Since it is using masses of ANSI strings this is some
> > performance problem.
> >
> > The strings get stored and loaded from TStringList's and concatenated
> > by simply using '+' and separated with the function copy().
>
> You could try to avoid repeated setlengths. However this would require
> two passes, something like
>
> tot:=0;
> for i:=0 to strlst.count-1 do inc(tot,length(strlst[i]));
> setlength(targetstring,tot);
> j:=1;
> for i:=0 to strlst.count-1 do
> begin
> move (targetstring[j],strlst[i]);
> inc(j,length(strlst[i]));
> end;
>
So in general reserving buffer space and copying all string in and
finally setting the length would be the way to go here, if I understand
correctly.
> Posting more code would help too.
See my other mail.
Thanks,
Marc
More information about the fpc-pascal
mailing list