Документ взят из кэша поисковой машины. Адрес
оригинального документа
: http://www.atnf.csiro.au/computing/software/casacore/casacore-1.2.0/doc/html/classcasa_1_1ObjectPool.html
Дата изменения: Unknown Дата индексирования: Mon Feb 14 21:36:39 2011 Кодировка: Поисковые слова: vallis |
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) |
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 |
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 99 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.
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 48 of file ObjectPool.h.
PoolStack<T, Key>& casa::ObjectPool< T, Key >::getStack | ( | const Key | key | ) |
Get the object stack for the given key.
uInt casa::ObjectPool< T, Key >::nelements | ( | ) | const [inline] |
Get the number of object stacks in the pool.
Definition at line 59 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 77 of file ObjectPool.h.
PoolStack<T, Key>* casa::ObjectPool< T, Key >::cacheStack_p [private] |
Definition at line 78 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 75 of file ObjectPool.h.
PoolStack<T, Key>* casa::ObjectPool< T, Key >::defStack_p [private] |
Definition at line 76 of file ObjectPool.h.
SimpleOrderedMap<Key, PoolStack<T, Key>* > casa::ObjectPool< T, Key >::map_p [private] |
The pool map.
Definition at line 82 of file ObjectPool.h.