[fpc-pascal] string concatenation speed

Marco van de Voort marcov at stack.nl
Tue Jun 21 19:21:49 CEST 2005

> 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

for i:=0 to strlst.count-1 do  inc(tot,length(strlst[i]));
for i:=0 to strlst.count-1 do 
    move (targetstring[j],strlst[i]);
> What I'd like to know is: What's are fastest ways of handling ANSI
> strings?

- avoid copying of strings if possible
- operate on pchar level in speed dependant parts.

> Since I'm not good at reading assembler code I have to ask ... and yes,
> profiling is planned but not for tomorrow. ;)

Posting more code would help too.

More information about the fpc-pascal mailing list