The string mdule is used for storing strings. It takes care of deallocations using the reference counts. It also prevents from storing the same string several times.
A string is handled using a variable of type string
.
It is a pointer to the following string_entry
structure:
uns length
uns ref_count
struct string_entry *dead_next
char text[1]
All the strings (string structure pointers) are stored in a hash table. The key into this hash table is the array of characters. The hash table contains pointers to all used strings to avoid memory leaks.
Most referenced objects are freed when the reference count decreases to zero. This is also true for strings if there is no transaction running. Strings which lose the last reference in a transaction are freed at the end of the transaction. So if a string is used only during one transaction, referencing the string is not necessary.