string types

ansistring types

The ansistring is a dynamically allocated string which has no length limitation. When the string is no longer being referenced (its reference count reaches zero), its memory is automatically freed.

If the ansistring is a constant, then its reference count will be equal to -1, indicating that it should never be freed. The structure in memory for an ansistring is shown in table (8.3).



Table 8.3: AnsiString memory structure (32-bit model)
Offset Contains


-12 Longint with maximum string size.
-8 Longint with actual string size.
-4 Longint with reference count.
0 Actual array of char, null-terminated.



shortstring types

A shortstring occupies as many bytes as its maximum length plus one. The first byte contains the current dynamic length of the string. The following bytes contain the actual characters (of type char) of the string. The maximum size of a short string is the length byte followed by 255 characters.

widestring types

The widestring (composed of unicode characters) is not supported in Free Pascal v1.0.