WvStreams
|
A cache table of WvString objects. More...
#include <wvstringcache.h>
Public Member Functions | |
WvString | get (WvStringParm s) |
Get a shared string corresponding to 's'. | |
void | clean () |
Remove any now-unused strings from the cache. |
A cache table of WvString objects.
If you think you might be reusing the same string objects over and over (for example, because the user provides the same string value a million times in a config file you're reading), you might be able to save a lot of memory by sharing the strings via a WvStringCache.
To potentially share a string, call get(string), throw away the input string, and use the output string (which is guaranteed to have the same content) in its place. The string will be saved in the cache table for next time.
Every once and a while, you should call clean() to remove any strings from the table that are no longer referenced elsewhere. This is especially important after deleting a large data structure, because you won't actually free up the memory used by those strings until clean() is called.
All WvStringCaches in the app are shared, to optimize the benefits of the cache.
Definition at line 32 of file wvstringcache.h.
Get a shared string corresponding to 's'.
Definition at line 39 of file wvstringcache.cc.
Referenced by UniListIter::add(), and UniTempGen::set().
void WvStringCache::clean | ( | ) |
Remove any now-unused strings from the cache.
Definition at line 58 of file wvstringcache.cc.