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)
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)
- the class T must have a constructor(T::FULLREFRESH)
for creating new entries and destructor;
and must possess a clear() method to enable element re-use.
To Do
Member Description
Destructor
static ObjectStack<T> &stack()
Create a singleton stack
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
Decimate the stack by getting rid of all unused elements in it
Test if stack empty
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)