casa
$Rev:20696$
|
A parameterized stack of re-usable objects. More...
#include <ObjectPool.h>
Public Member Functions | |
ObjectPool () | |
Create the pool. | |
~ObjectPool () | |
Delete the pool. | |
T * | get (const Key key=Key()) |
Get a pointer to an object in the pool with the specified parameter. | |
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. | |
Private Member Functions | |
ObjectPool (const ObjectPool< T, Key > &other) | |
Copy and assignment constructors and assignment (not implemented) | |
ObjectPool< T, Key > & | operator= (const ObjectPool< T, Key > &other) |
void | doClearStack (const Key key) |
Do the actual clearing of the stack (without a lock). | |
Private Attributes | |
Key | defKey_p |
The default key and stack, and the last referenced one (for caching purposes) | |
PoolStack< T, Key > * | defStack_p |
Key | cacheKey_p |
PoolStack< T, Key > * | cacheStack_p |
Mutex | mutex_p |
SimpleOrderedMap< Key, PoolStack< T, Key > * > | map_p |
The pool map. |
A parameterized stack of re-usable objects.
Public interface
An ObjectPool contains a set of pre-allocated Objects of the type T
. A Map based on the Key
values contains a stack of objects for each key value.
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);
To improve the speed for the auto differentiating class.
Definition at line 101 of file ObjectPool.h.
casa::ObjectPool< T, Key >::ObjectPool | ( | ) |
Create the pool.
casa::ObjectPool< T, Key >::~ObjectPool | ( | ) |
Delete the pool.
casa::ObjectPool< T, Key >::ObjectPool | ( | const ObjectPool< T, Key > & | other | ) | [private] |
Copy and assignment constructors and assignment (not implemented)
void casa::ObjectPool< T, Key >::clear | ( | ) |
Decimate the stacks and remove any map entry that is completely unused.
void casa::ObjectPool< T, Key >::clearStack | ( | const Key | key = Key() | ) |
void casa::ObjectPool< T, Key >::clearStacks | ( | ) |
Decimate the stacks by deleting all unused objects.
void casa::ObjectPool< T, Key >::doClearStack | ( | const Key | key | ) | [private] |
Do the actual clearing of the stack (without a lock).
T* casa::ObjectPool< T, Key >::get | ( | const Key | key = Key() | ) | [inline] |
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.
Definition at line 114 of file ObjectPool.h.
PoolStack<T, Key>& casa::ObjectPool< T, Key >::getStack | ( | const Key | key | ) |
Get the object stack for the given key.
Referenced by casa::ObjectPool< AutoDiffRep< Float >, uInt >::get().
uInt casa::ObjectPool< T, Key >::nelements | ( | ) | const [inline] |
Get the number of object stacks in the pool.
Definition at line 125 of file ObjectPool.h.
ObjectPool<T, Key>& casa::ObjectPool< T, Key >::operator= | ( | const ObjectPool< T, Key > & | other | ) | [private] |
void casa::ObjectPool< T, Key >::release | ( | T * | obj, |
const Key | key = Key() |
||
) |
Release an object obtained from the pool through get
for re-use.
Referenced by casa::AutoDiff< Double >::release().
Key casa::ObjectPool< T, Key >::cacheKey_p [private] |
Definition at line 143 of file ObjectPool.h.
PoolStack<T, Key>* casa::ObjectPool< T, Key >::cacheStack_p [private] |
Definition at line 144 of file ObjectPool.h.
Key casa::ObjectPool< T, Key >::defKey_p [private] |
The default key and stack, and the last referenced one (for caching purposes)
Definition at line 141 of file ObjectPool.h.
PoolStack<T, Key>* casa::ObjectPool< T, Key >::defStack_p [private] |
Definition at line 142 of file ObjectPool.h.
SimpleOrderedMap<Key, PoolStack<T, Key>* > casa::ObjectPool< T, Key >::map_p [private] |
The pool map.
Definition at line 149 of file ObjectPool.h.
Referenced by casa::ObjectPool< AutoDiffRep< Float >, uInt >::nelements().
Mutex casa::ObjectPool< T, Key >::mutex_p [private] |
Definition at line 145 of file ObjectPool.h.