As an example, a <Vector<Double>, uInt> ObjectPool contains a SimpleOrderedMap<uInt,PoolStack<Vector<Double>,uInt>* > map. Each Stack will contain a stack of Vector<Double> objects, with a length of the key value each.
When an object is asked for with the get method, the correct stack is found using the parameter key. If no entry in the map exists, a new stack is created. If the relevant stack is empty, new elements are added to the stack.
// Create a pool of vectors ObjectPool<Vector<Double>, uInt> pool; // Get a pointer to a pre-defined vector of length 5 Vector<Double> *el5(pool.get(5)); // and one of length 10 Vector<Double> *el10(pool.get(10)); ... // Release the objects for re-use pool.release(el5, 5); pool.release(el10, 10); </srcblock </example> <motivation> To improve the speed for the auto differentiating class. </motivation> <templating arg=T> <li> the class T must have a constructor with a Key argument </templating> <templating arg=Key> <li> the class Key must be sortable to be used as a key in the Map </templating> <todo asof="2001/06/07"> <li> Nothing at the moment </todo>Member Description
ObjectPool()
Create the pool~ObjectPool()
Delete the poolT *get(const Key key=Key())
Get a pointer to an object in the pool with the specified parameter. The object is detached from the stack, and has to be returned with the release method. The object should not be deleted by caller.
PoolStack<T, Key> &getStack(const Key key)
Get the object stack for the given key
void release(T *obj, const Key key=Key())
Release an object obtained from the pool through get for re-use.
uInt nelements() const
Get the number of object stacks in the pool
void clearStacks()
Decimate the stacks by deleting all unused objects.
void clearStack(const Key key=Key())void clear()
Decimate the stacks and remove any map entry that is completely unused
ObjectPool(const ObjectPool<T, Key> &other)
ObjectPool<T, Key> &operator=(const ObjectPool<T, Key> &other)Copy and assignment constructors and assignment (not implemented)