[fpc-pascal] When is AnsiString not a good substitute for string?

Jonas Maebe jonas.maebe at elis.ugent.be
Sun Mar 21 21:28:36 CET 2010


On 21 Mar 2010, at 21:07, Jorge Aldo G. de F. Junior wrote:

> actually, for most porpuses, ansistring is a lot faster than normal
> strings with size 255...
> 
> you pass around 4 bytes instead of 256...

And on the downside the compiler inserts a lot of initialisation/finalisation and reference increment/decrement code for ansistrings (which use atomic operations and hence are fairly slow), and if you use var/out/const parameters then the compiler will also pass around pointers to shortstrings instead of copying them all the time.

Unless you are assigning long strings to each other all the time (or if your string parameters are all value parameters even though you don't change them), I don't think ansistrings are much if any faster than shortstrings. In fact, the compiler internally uses shortstrings instead of ansistrings in a lot of places exactly because of speed reasons.


Jonas


More information about the fpc-pascal mailing list