[Crossfire-wiki] [Crossfire DokuWiki] page changed: dev:shared_strings

no-reply_wiki at metalforge.org no-reply_wiki at metalforge.org
Thu Mar 22 08:19:42 CDT 2007


A page in your DokuWiki was added or changed. Here are the details:

Date        : 2007/03/22 08:19
User        : ryo
Edit Summary: merge stuff from dev:objects

@@ -1,5 +1,5 @@
- 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.
+ 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:
@@ -13,4 +13,6 @@
    * ''const char* add_string(const char *str)'', used to share a string. Returned value is a string with the same contents that can be shared with other objects
    * ''const char* add_refcount(const char *str)'', equivalent of ''add_string'' when the string is already a shared string
    * ''const char* find_string(const char *str)'', to search if a string is shared or not
    * ''void free_string(const char *str)'', to decrement the use counter. After it's called, ''str'' should not be used anymore.
+ 
+ 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).


IP-Address  : 172.186.46.252
Old Revision: http://wiki.metalforge.net/doku.php/dev:shared_strings?rev=1174562962
New Revision: http://wiki.metalforge.net/doku.php/dev:shared_strings

-- 
This mail was generated by DokuWiki at
http://wiki.metalforge.net/




More information about the crossfire-wiki mailing list