StringManager |
StringManagerThe StringManager is the abstract table storing all the shared strings. Shared strings register/unregister themselves with the manager, which keeps tracks of reference counts for each allocated string. When a string no longer has any references, the memory is freed. Strings are managed via SharedStringEntries. AuthorDavid C. Haley (david at the-haleys dot com) Summary
countRefs
Count the number of times a string is referenced. If the string is not in the manager table, it is referenced 0 times. AuthorDavid C. Haley (david at the-haleys dot com) Parameters
ReturnsThe number of references to a given string. bytesUsed
Return how many bytes are used by the shared string manager. Includes memory for the shared strings, the table to store them, plus any overhead. Note that due to byte padding, structures may be larger than you might expect. AuthorDavid C. Haley (david at the-haleys dot com) ReturnsThe total number of bytes used by this shared string table. dumpTable
Dump the shared string table to an output stream. The format of this output is left to the subclass implementations. Generally it will contain a textual representation of table structure as well as the managed strings. NoteThis function is pure virtual. Subclasses must implement it. UsageaTable->dumpTable(cout); // dump table to cout AuthorDavid C. Haley (david at the-haleys dot com) Parameters
prepareEntry
Get an entry in the table for a given string, creating if necessary. The intention of this function is that you call it when adding a new string to the table: it will look up and return the right entry whose refcount to increment, or it will create a new, empty entry. NoteThis function is pure virtual. Subclasses must implement it. AuthorDavid C. Haley (david at the-haleys dot com) Parametersstr - Returns... unrefEntry
Decrease the reference count of a shared string. Frees memory if the string’s refcount drops to zero. NoteThis function is pure virtual. Subclasses must implement it. Parameters
ReturnsTrue if the entry’s refcount went to zero and was deleted. getEntry
Get an entry in the shared string table. Returns null if there is no such entry. NoteThis function is pure virtual. Subclasses must implement it. AuthorDavid C. Haley (david at the-haleys dot com) Parameters
ReturnsThe shared string table entry corresponding to /str/. SharedStringEntryThe StringManager manages a collection of SharedStringEntries. A SharedStringEntry is a paired reference count and std::string object. DECLARE_MANAGER_WRAPPERDeclares a shared string wrapper. This macro should be executed in your header files whenever you want to make visible your shared string class. After declaring a wrapper, you should define it using the macro ASSOCIATE_MANAGER_WRAPPER in a C++ source file. UsageTypical usage would be something like soDECLARE_MANAGER_WRAPPER(HashTableWrapper); Parameters
ASSOCIATE_MANAGER_WRAPPERAssociates a declared wrapper with a table manager. This macro should be executed once in a C++ source file. It is important that you use the macro once, as changing the wrapper’s manager could have unpredictable consequences. NoteYou may associate the wrapper with a manager at any point of time during program execution. That being said, you must have a wrapper associated the first time you use a shared string. UsageAfter having defined a wrapper -HashTableWrapper- using DECLARE_MANAGER_WRAPPER, typical usage would be something like so: SharedString::HashTable * gTable; Parameters
|
Add a string reference to the manager.
const std::string * addString( const std:: string & str )
Remove a string reference from the manager.
void deleteString( const std:: string & str )
Count the number of times a string is referenced.
size_t countRefs( const std:: string & str ) const
Returns the number of unique strings in the table.
size_t numStrings() const
Return how many bytes are used by the shared string manager.
virtual size_t bytesUsed() const = 0
Dump the shared string table to an output stream.
virtual void dumpTable( std:: ostream & os ) const = 0
Total number of (unique) strings
size_t numStrings_
Get an entry in the table for a given string, creating if necessary.
virtual SharedStringEntry * prepareEntry( const std:: string & str ) = 0
Decrease the reference count of a shared string.
virtual bool unrefEntry( const std:: string & str ) = 0
Get an entry in the shared string table.
virtual const SharedStringEntry * getEntry( const std:: string & str ) const = 0