Clipper
|
Object Cache manager. More...
#include <clipper_memory.h>
Classes | |
class | Reference |
ObjectCache reference class. More... | |
Public Types | |
enum | MODE { NORMAL, MINMEM, MAXMEM } |
Public Member Functions | |
ObjectCache () | |
constructor | |
~ObjectCache () | |
destructor, can message on contents | |
void | set_mode (const MODE &mode) |
set garbage collection mode | |
void | purge () |
purge unreferenced objects from cache | |
void | destroy () |
VERY DANGEROUS, DO NOT USE. | |
void | debug () const |
Reference | cache (const typename T::Key &key) |
cache or return data by key |
Object Cache manager.
The object cache is a tool for storing information which may appear several times. Examples include tables of information for spacegroups or crystallographic maps. When a new object is created, a check is first done to see if such an object already exists in the cache, in which case that copy is used. Otherwise a new copy is added to the cache.
A cached object must implement:
Referring to the cache returns an ObjectCache<T>::Reference to a cache object. This object performs reference counting, which is used for garbage collection.
To retrieve the actual cached data, use the ObjectCache<T>::Reference::data() method. The data is held at a fixed memory location, therefore pointers to the data may be safely kept, as long as they are discarded as soon as the reference is discarded (at which point garbage collection may occur).
Ideally this would be a class with static members only, but some compilers have trouble with static members of template classes.
Garbage collection modes include: