clipper::ObjectCache< T > Class Template Reference

Object Cache manager. More...

#include <clipper_memory.h>

List of all members.

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 debug () const
template<class K>
Reference cache (const K &key)
 cache or return data by key

Friends

class ObjectCache< T >::Reference

Classes

class  Reference
 ObjectCache reference class. More...


Detailed Description

template<class T>
class clipper::ObjectCache< T >

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.


Member Function Documentation

template<class T>
void clipper::ObjectCache< T >::set_mode ( const MODE &  mode  )  [inline]

set garbage collection mode

Garbage collection modes include:

  • ObjectCache<T>::NORMAL : Remove an old object only when a new object is required and an old object is no longer in use. (default)
  • ObjectCache<T>::MINMEM : Remove an old object as soon as it is no longer in use.
  • ObjectCache<T>::MAXMEM : Never remove old objects. The more memory hungry modes may improve performance for some problems where a new object may be created which was already used and destroyed before.
    Parameters:
    mode The garbage collection mode.

template<class T>
void clipper::ObjectCache< T >::purge (  )  [inline]

purge unreferenced objects from cache

Any cached objects with a reference count of 0 will be purged. This also happens when adding an object in MINMEM mode.


The documentation for this class was generated from the following file:

Generated on Mon Feb 18 18:09:27 2008 for Clipper by  doxygen 1.5.5