[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

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;
 
> 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