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’s life. Using shared strings saves memory and improved performance.

Those strings are used like regular const char*, but should not be changed via strcpy, snprintf or other means 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.

To alter such a string, the right behaviour is:

FIXME replace with sstring when done in code

To manipulate them, the following functions (defined in common/shstr.c) are available:

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 str == str2 directly).

 
dev/shared_strings.txt · Last modified: 2007/03/22 08:19 by ryo
 
Recent changes RSS feed Powered by PHP Valid XHTML 1.0 Valid CSS Debian Driven by DokuWiki