StaticObjectPool< T > Class Template Reference

An object pool that allocates (presumably fixed-size) objects in a contiguous memory buffer. More...

#include <StaticObjectPool.h++>

Inheritance diagram for StaticObjectPool< T >:
Inheritance graph
[legend]

List of all members.

Classes

struct  Link

Public Member Functions

 StaticObjectPool (size_t size)
 Construct a new StaticObjectPool of the given size.
 ~StaticObjectPool () throw ()
 Destructor.
T * reserve () throw (ObjectPoolException)
 Reserve an object from the pool.
void release (T *elem) throw (ObjectPoolException)
 Release an object back to the pool.
size_t getSize () const throw ()
 Get the size of the pool, i.e., the total number of objects (both reserved and available) in the pool.
uint_t getAvailable () const throw ()
 Get the number of available (unreserved) objects in the pool.

Protected Attributes

size_t _size
 The size of the pool (i.e., the maximum number of objects managed by the pool).
uint_t _avail
 The number of objects currently available (not reserved) in the pool.

Detailed Description

template<typename T>
class ccxx::StaticObjectPool< T >

An object pool that allocates (presumably fixed-size) objects in a contiguous memory buffer.

This class is not suitable for objects which allocate additional member data on the heap, as this data will be created each time an object is reserved from the pool and destroyed when it is released back to the pool; use DynamicObjectPool in this case.

Author:
Mark Lindner

Constructor & Destructor Documentation

StaticObjectPool ( size_t  size  ) 

Construct a new StaticObjectPool of the given size.

Parameters:
size The number of objects to allocate in the pool.
~StaticObjectPool (  )  throw ()

Destructor.

Deallocates all of the objects in the pool. Destructors will not be called for any objects still allocated from the pool; therefore it is a programmig error to destroy a StaticObjectPool before releasing all of its objects.


Member Function Documentation

uint_t getAvailable (  )  const throw () [inline, inherited]

Get the number of available (unreserved) objects in the pool.

size_t getSize (  )  const throw () [inline, inherited]

Get the size of the pool, i.e., the total number of objects (both reserved and available) in the pool.

void release ( T *  elem  )  throw (ObjectPoolException) [virtual]

Release an object back to the pool.

The object's destructor is called before the object is released back to the pool.

Parameters:
elem The object to release.
Exceptions:
ObjectPoolException If elem is NULL.

Implements ObjectPool< T >.

T* reserve (  )  throw (ObjectPoolException) [virtual]

Reserve an object from the pool.

The object's constructor is called before the object is returned.

Returns:
A pointer to the reserved object.
Exceptions:
ObjectPoolException If there are no more objects available in the pool.

Implements ObjectPool< T >.


Member Data Documentation

uint_t _avail [protected, inherited]

The number of objects currently available (not reserved) in the pool.

size_t _size [protected, inherited]

The size of the pool (i.e., the maximum number of objects managed by the pool).


The documentation for this class was generated from the following file:
Generated on Sat Nov 26 16:49:09 2011 for libcommonc++ by  doxygen 1.6.3