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. WHS size is 4 bytes for all versions of Free Pascal.
  4. UHS size is 8 bytes for all versions of Free Pascal.


Table 3.6: String memory sizes

String type Stack size heap size



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