ObjectStack.h

Classes

ObjectStack -- A stack of re-usable objects (full description)

template <class T> class ObjectStack

Interface

Public Members
~ObjectStack()
static ObjectStack<T> &stack()
T *get()
void put(T *obj)
void clear()
Bool empty()
uInt nelements() const
Private Members
ObjectStack() : stack_p()
ObjectStack(const ObjectStack<T> &other)
ObjectStack<T> &operator=(const ObjectStack<T> &other)

Description

Review Status

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

Prerequisite

Synopsis

An ObjectStack contains a set of pre-allocated Objects of the type T. 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 AutoDiff classes, but can be used independently. The stack works best with small object sizes, or letter/envelope classes.

Example

   {
   // Get an element (and create stack!)
   SparseDiff<Double> elem;
   // Use it
   elem.value() = 27;
   // Release it (automatic by dtor on elem)
   }

Motivation

To improve the speed for the auto differentiating classes.

Template Type Argument Requirements (T)

To Do

Member Description

~ObjectStack()

Destructor

static ObjectStack<T> &stack()

Create a singleton stack

T *get()

Get a pointer to an object in the stack. The stack will be extended if no objects left.

void put(T *obj)

Return an object to the stack for re-use

void clear()

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

Bool empty()

Test if stack empty

uInt nelements() const

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

ObjectStack() : stack_p()
ObjectStack(const ObjectStack<T> &other)
ObjectStack<T> &operator=(const ObjectStack<T> &other)

All ctor and assignment constructors and assignment (not implemented)