MUniqueStringCache can be used to map strings to unique ids.
More...
List of all members.
Detailed Description
MUniqueStringCache can be used to map strings to unique ids.
The mapping is backed up by a file on disk which will be mmaped into memory at runtime. Therefor the ids can be shared between several running programs. Additionally the memory occupied by the strings will be shared between the processes. Proper locking will make sure that two processes cannot add strings to the cache at the same time. Reading values from the cache happens without locking.
Member Typedef Documentation
Constructor & Destructor Documentation
MUniqueStringCache::MUniqueStringCache |
( |
const QString & |
filename |
) |
|
MUniqueStringCache::~MUniqueStringCache |
( |
|
) |
|
Member Function Documentation
Converts a given index into a string.
This lookup is very fast.
bool MUniqueStringCache::isAttached |
( |
|
) |
|
Returns true when the cache is properly attached to the file on disk.
bool MUniqueStringCache::isLocked |
( |
|
) |
|
Return true if the cache is locked.
bool MUniqueStringCache::lock |
( |
|
) |
|
indexToString() and stringToIndex() internally automatically lock the cache to ensure that no two processes are changing the cache at the same time.
If you know that the cache needs to be locked very often, e.g. because stringToIndex() is called often with strings likely not in the cache, this method can be used to lock it just once. This avoids the need to lock and unlock it seperately for every call to stringToIndex(). Make sure to call unlock() after all strings have been processed.
Returns the id for a given string.
If the string is not in the cache yet it will be added. If possible use this function only to fill the cache. To work it needs to read in the whole cache file to find the given string. Depending on the cache size this might be costly.
bool MUniqueStringCache::unlock |
( |
|
) |
|
Unlocks the cache formerly locked with lock().
Member Data Documentation