PoolStack.h

Classes

PoolStack -- A parameterized stack of re-usable objects (full description)

template <class T, class Key> class PoolStack

Interface

Public Members
PoolStack()
explicit PoolStack(const Key &key)
~PoolStack()
T *get()
void release(T *obj)
void addElements(const uInt n)
void clear()
Bool empty()
const Key &key() const
uInt nelements() const
Private Members
PoolStack(const PoolStack<T, Key> &other)
PoolStack<T, Key> &operator=(const PoolStack<T, Key> &other)

Description

Review Status

Reviewed By:
Ger van Diepen
Date Reviewed:
2001/07/03
Programs:
Tests:

Prerequisite

Synopsis

A PoolStack contains a set of pre-allocated Objects of the type T, with a parameter Key (e.g. an object could be a Vector of T Double with an uInt Key). The stack is a very simple stack, without the linking/unlinking of a normal Stack implementation. This lightweight implementation was especially designed for use with the ObjectPool class, but can be used independently.

Objects can be obtained with the get() method, and returned for re-use with release().

Objects are not initialised when popped. The user should never delete the object returned by get; but return it to the pool.

Example

   // Create a pool of length 5 vectors
   PoolStack<Vector<Double>, uInt> pool5(5);
   // Get an element
   Vector<Double> *elem(pool5.get());
   // Use it
   (*elem)(2) = 27;
   // Release it
   pool5.release(elem);

Motivation

To improve the speed for the auto differentiating class.

Template Type Argument Requirements (T)

Template Type Argument Requirements (Key)

To Do

Member Description

PoolStack()

Create the stack with the default Key

explicit PoolStack(const Key &key)

Create the stack for the specified key

~PoolStack()

Delete the stack

T *get()

Get a pointer to an object in the stack. The stack will be extended if no objects left. Extension is done with the NDEF number of elements. Different extension can be done manually with the addElements() method.

void release(T *obj)

Return an object to the stack for re-use

void addElements(const uInt n)

Add n elements

void clear()

Decimate the stack by getting rid of all unused elements in it

Bool empty()

Test if stack empty

const Key &key() const

Return the key belonging to the stack

uInt nelements() const

return the stack extend (for debugging use and checking mainly)

PoolStack(const PoolStack<T, Key> &other)
PoolStack<T, Key> &operator=(const PoolStack<T, Key> &other)

Copy and assignment constructors and assignment (not implemented)