casacore
Public Member Functions | Private Member Functions | Private Attributes | List of all members
casacore::ObjectPool< T, Key > Class Template Reference

A parameterized stack of re-usable objects. More...

#include <ObjectPool.h>

Public Member Functions

 ObjectPool ()
 Create the pool. More...
 
 ~ObjectPool ()
 Delete the pool. More...
 
T * get (const Key key=Key())
 Get a pointer to an object in the pool with the specified parameter. More...
 
PoolStack< T, Key > & getStack (const Key key)
 Get the object stack for the given key. More...
 
void release (T *obj, const Key key=Key())
 Release an object obtained from the pool through get for re-use. More...
 
uInt nelements () const
 Get the number of object stacks in the pool. More...
 
void clearStacks ()
 Decimate the stacks by deleting all unused objects. More...
 
void clearStack (const Key key=Key())
 
void clear ()
 Decimate the stacks and remove any map entry that is completely unused. More...
 

Private Member Functions

 ObjectPool (const ObjectPool< T, Key > &other)
 Copy and assignment constructors and assignment (not implemented) More...
 
ObjectPool< T, Key > & operator= (const ObjectPool< T, Key > &other)
 
void doClearStack (const Key key)
 Do the actual clearing of the stack (without a lock). More...
 

Private Attributes

Key defKey_p
 The default key and stack, and the last referenced one (for caching purposes) More...
 
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. More...
 

Detailed Description

template<class T, class Key>
class casacore::ObjectPool< T, Key >

A parameterized stack of re-usable objects.

Intended use:

Public interface

Review Status

Reviewed By:
Ger van Diepen
Date Reviewed:
2001/07/04
Test programs:
tObjectPool

Prerequisite

Synopsis

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.

Example

// 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);

Motivation

To improve the speed for the auto differentiating class.

Template Type Argument Requirements (T)

Template Type Argument Requirements (Key)

To Do

Definition at line 101 of file ObjectPool.h.

Constructor & Destructor Documentation

◆ ObjectPool() [1/2]

template<class T, class Key>
casacore::ObjectPool< T, Key >::ObjectPool ( )

Create the pool.

◆ ~ObjectPool()

template<class T, class Key>
casacore::ObjectPool< T, Key >::~ObjectPool ( )

Delete the pool.

◆ ObjectPool() [2/2]

template<class T, class Key>
casacore::ObjectPool< T, Key >::ObjectPool ( const ObjectPool< T, Key > &  other)
private

Copy and assignment constructors and assignment (not implemented)

Member Function Documentation

◆ clear()

template<class T, class Key>
void casacore::ObjectPool< T, Key >::clear ( )

Decimate the stacks and remove any map entry that is completely unused.

Referenced by casacore::ObjectPool< casacore::AutoDiffRep< T >, uInt >::nelements().

◆ clearStack()

template<class T, class Key>
void casacore::ObjectPool< T, Key >::clearStack ( const Key  key = Key())

◆ clearStacks()

template<class T, class Key>
void casacore::ObjectPool< T, Key >::clearStacks ( )

Decimate the stacks by deleting all unused objects.

Referenced by casacore::ObjectPool< casacore::AutoDiffRep< T >, uInt >::nelements().

◆ doClearStack()

template<class T, class Key>
void casacore::ObjectPool< T, Key >::doClearStack ( const Key  key)
private

Do the actual clearing of the stack (without a lock).

◆ get()

template<class T, class Key>
T* casacore::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.

◆ getStack()

template<class T, class Key>
PoolStack<T, Key>& casacore::ObjectPool< T, Key >::getStack ( const Key  key)

Get the object stack for the given key.

Referenced by casacore::ObjectPool< casacore::AutoDiffRep< T >, uInt >::get().

◆ nelements()

template<class T, class Key>
uInt casacore::ObjectPool< T, Key >::nelements ( ) const
inline

Get the number of object stacks in the pool.

Definition at line 125 of file ObjectPool.h.

◆ operator=()

template<class T, class Key>
ObjectPool<T, Key>& casacore::ObjectPool< T, Key >::operator= ( const ObjectPool< T, Key > &  other)
private

◆ release()

template<class T, class Key>
void casacore::ObjectPool< T, Key >::release ( T *  obj,
const Key  key = Key() 
)

Release an object obtained from the pool through get for re-use.

Referenced by casacore::ObjectPool< casacore::AutoDiffRep< T >, uInt >::get(), and casacore::AutoDiff< T >::release().

Member Data Documentation

◆ cacheKey_p

template<class T, class Key>
Key casacore::ObjectPool< T, Key >::cacheKey_p
private

Definition at line 143 of file ObjectPool.h.

◆ cacheStack_p

template<class T, class Key>
PoolStack<T, Key>* casacore::ObjectPool< T, Key >::cacheStack_p
private

Definition at line 144 of file ObjectPool.h.

◆ defKey_p

template<class T, class Key>
Key casacore::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.

◆ defStack_p

template<class T, class Key>
PoolStack<T, Key>* casacore::ObjectPool< T, Key >::defStack_p
private

Definition at line 142 of file ObjectPool.h.

◆ map_p

template<class T, class Key>
SimpleOrderedMap<Key, PoolStack<T, Key>* > casacore::ObjectPool< T, Key >::map_p
private

The pool map.

Definition at line 149 of file ObjectPool.h.

Referenced by casacore::ObjectPool< casacore::AutoDiffRep< T >, uInt >::nelements().

◆ mutex_p

template<class T, class Key>
Mutex casacore::ObjectPool< T, Key >::mutex_p
private

Definition at line 145 of file ObjectPool.h.


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