[Lazarus] Strings

Jürgen Hestermann juergen.hestermann at gmx.de
Wed Nov 18 07:12:24 CET 2009



> And I think shortstring should generally be discouraged. The standard is
> always "255 is enough", but sooner or later somebody hits it:

That's like saying that short integer types like byte or word should be discouraged and only Int64 should be used. 

Shortstrings are just a completely different string type than ansistrings. Therefore it is dangerous to use the generic string type because in general a programer needs to know how the strings are stored, otherwise significant bugs are likely. With Shortsstrings you don't have to think about reference counters and other traps that can be cause hard to find errors (i.e. when using ansistrings within a highly nested data structure). Just think of a array of strings. If shortsstrings are used, all data is in one block of memory. You can move it around and make copies of it. But with ansistring this is not so easy. You only have an array of pointers. If you use move() on such an array then the reference counters are not affected and you get into trouble.




More information about the Lazarus mailing list