dev:shared_strings
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
dev:shared_strings [2007/03/22 08:19] – external edit 127.0.0.1 | dev:shared_strings [2025/04/18 13:08] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | To minimize memory use, Crossfire uses a shared string mechanism. This is intended to be used for strings whose contents is not expected to change during the server' | + | ====== Shared String ====== |
- | Those strings are used like regular '' | + | To minimize memory use, Crossfire uses a shared string |
+ | This is intended | ||
+ | Using shared strings saves memory and improved performance. | ||
+ | Those strings are used like regular '' | ||
+ | but should not be changed via '' | ||
+ | because it would affect **all** structures using the shared string. \\ | ||
+ | Internally, they use a counter to track at how many places they are used. \\ | ||
+ | When it reaches 0, string is freed. | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Shared String Manipulation == | ||
To alter such a string, the right behaviour is: | To alter such a string, the right behaviour is: | ||
* write new value in a '' | * write new value in a '' | ||
Line 8: | Line 19: | ||
* call '' | * call '' | ||
- | FIXME replace | + | To manipulate them, the following functions defined in \\ |
+ | [[http:// | ||
+ | are available: | ||
+ | * Old: '' | ||
+ | * New: ** '' | ||
+ | * Used to share an existing string. | ||
+ | * Returned value is a string | ||
+ | * Returns return hash_table[ind]-> | ||
+ | |||
+ | * Old: '' | ||
+ | * New: ** '' | ||
+ | * This will increase the refcount of the string str. | ||
+ | * String str which *must* have been returned from a previous add_string(). | ||
+ | * :?: Equivalent of '' | ||
+ | |||
+ | |||
+ | * Old: '' | ||
+ | * New: ** '' | ||
+ | * To search if a string is shared or not. | ||
+ | * Returns pointer to identical string or NULL . | ||
+ | |||
+ | |||
+ | * Old: '' | ||
+ | * New: ** '' | ||
+ | * To decrement the use refcount counter. | ||
+ | * *Must* have been returned from a previous add_string(). | ||
+ | * After it's called, '' | ||
+ | |||
+ | Because shared strings will return a pointer to a string if it exists, \\ | ||
+ | one can see if the strings are equal by comparing the shared string address they point to (ie '' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== SSTRING ===== | ||
+ | sstring is defined | ||
+ | <code c> | ||
+ | /** | ||
+ | * One actual shared string. | ||
+ | */ | ||
+ | typedef struct _shared_string { | ||
+ | union { | ||
+ | struct _shared_string **array; | ||
+ | struct _shared_string *previous; | ||
+ | } u; | ||
+ | struct _shared_string *next; | ||
+ | /* The top bit of " | ||
+ | * at the array entry. | ||
+ | */ | ||
+ | unsigned REFCOUNT_TYPE refcount; | ||
+ | /* Padding will be unused memory, since we can't know how large | ||
+ | * the padding when allocating memory. We assume here that | ||
+ | * sizeof(long) is a good boundary. | ||
+ | */ | ||
+ | char string[PADDING]; | ||
+ | } shared_string; | ||
+ | </code> | ||
+ | |||
+ | ---- | ||
- | To manipulate them, the following functions (defined in '' | + | ===== Trivial == |
- | * '' | + | < |
- | * '' | + | /** |
- | * '' | + | * @file shstr.c |
- | * '' | + | |
+ | * | ||
+ | | ||
+ | */ | ||
+ | </ | ||
- | Because shared strings will return a pointer to a string if it exists, one can see if the strings are equal by comparing the shared string address they point to (ie '' |
dev/shared_strings.1174569577.txt.gz · Last modified: (external edit)