Previous: Clipboard, Up: Kernel

6.7 Strings

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
The length of the string, not including the terminating `\0' character.
uns ref_count
The number of references.
struct string_entry *dead_next
A node of the dead list. See below.
char text[1]
A null-terminated array of characters which is stored in this string.

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.