[fpc-pascal] Speed question for strings
L505
fpc505 at z505.com
Sat Nov 19 10:53:55 CET 2005
> The first string is always long, so you are doing twice adding a small
> string to a long string. This causes much heap fragmentation.
>
> Try result:= result + (Line + #13#10);
> or
>
> Line := Line + #13#10;
> Result := Result + Line;
Ahh that will probably do the trick. I'll let you know.
>
> OTOH using a TStringList is probably faster, because strings are only
> concatenated once.
>
It's funny you mention that.. because the entire point of this unit (StrWrap1) is to
reinvent a stringlist actually. The classes unit hauls in lots of kilobytes.. so I'm
reinventing simple stringlists in a procedural manner.
It is useful for CGI applications and etc. so that
-uploading CGI application size is not so big.
-Classes unit hauls in a lot of kilobytes even with smartlinking.
(Not so important these days. But is with CGI)
-StrLoadFile is cleaner than using free and create, and stringlist.text
So the code is more clear, but the advanced features that stringlists have such as
sorting are not available obviously. It's basically an alternative to stringlists, in
a more compact and cleaner manner for *some* situations (not all.. I still use
stringlists for the times when needed).
After I'm done fiddling with these string concatenations (and the results are in), I
will most likely load the file right into a string via one call (instead of char by
char or line by line). But without using a TMemoryStream. I'll be doing it the hard
way (no classes unit allowed).
--
L505
More information about the fpc-pascal
mailing list