The memory occupied by a string depends on the string type. Some string types allocate the string data in memory on the heap, others have the string data on the stack. Table table (3.6) summarizes the memory usage of the various string types for the various string types. In the table, the following symbolic constants are used:
String type | Stack size | heap size |
Shortstring | Declared length + 2 | 0 |
Ansistring | Pointer size | L + 1 + HS |
Widestring | Pointer size | 2*(L + 1) + WHS |
UnicodeString | Pointer size | 2*(L + 1) + UHS |
Pchar | Pointer size | L+1 |