The ansistring is a dynamically allocated string which has no length limitation (other than addressable memory). 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) for 32-bit programs, and table (8.4) for 64-bit programs
Offset | Contains |
-12 | Code page indicator (2 bytes). |
-10 | Character size (2 bytes) |
-8 | Longint with reference count. |
-4 | Longint with actual string size. |
0 | Actual array of char, null-terminated. |
Offset | Contains |
-24 | Code page indicator (2 bytes). |
-22 | Character size (2 bytes) |
-16 | Sizeint with reference count. |
-8 | Sizeint with actual string size. |
0 | Actual array of char, null-terminated. |
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.
A unicode string is allocated on the heap, much like an ansistring. Unlike the ansistring, a unicodestring takes 2 bytes per character, and is terminated with a double null. It is reference counted just like an ansistring. The structure in memory for a unicodestring is shown in table (8.3) for 32-bit programs, and table (8.4) for 64-bit programs
Offset | Contains |
-8 | Longint with reference count. |
-4 | Longint with actual string size. |
0 | Actual array of char, null-terminated. |
Offset | Contains |
-16 | SizeInt with reference count. |
-8 | SizeInt with actual string size. |
0 | Actual array of char, null-terminated. |
On Non-Windows platforms, the widestring type is equal to the unicode string type.
On Windows platforms, a widestring is allocated on the heap, much like a unicode string, and is terminated with a double null. In difference with a unicode string, it is not reference counted.