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.7) summarizes the memory usage of the various string types for the various string types. In the table, the following symbolic constants are used:
L is the actual length of the string.
HS depends on the version of Free Pascal, but is 16 bytes as of Free Pascal 2.7.1.
UHS size is 8 bytes for all versions of Free Pascal.
On Windows, WHS size is 4 bytes for all versions of Free Pascal. On all other platforms, WHS equals UHS because the WideString type equals the UnicodeString type.
|String type||Stack size||heap size|
|Shortstring||Declared length + 1||0|
|Ansistring||Pointer size||L + 1 + HS|
|Widestring||Pointer size||2*(L + 1) + WHS|
|UnicodeString||Pointer size||2*(L + 1) + UHS|