3.2.8 String sizes

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:

  1. L is the actual length of the string.
  2. HS depends on the version of Free Pascal, but is 16 bytes as of Free Pascal 2.7.1.
  3. UHS size is 8 bytes for all versions of Free Pascal.
  4. 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.

Table 3.6: String memory sizes

String type Stack size heap size

Shortstring Declared length + 10
Ansistring Pointer size L + 1 + HS
Widestring Pointer size 2*(L + 1) + WHS
UnicodeStringPointer size 2*(L + 1) + UHS
Pchar Pointer size L+1