libcommonc++  0.7
ObjectPool< T > Class Template Referenceabstract

A base class for object pools. More...

#include <ObjectPool.h++>

Inheritance diagram for ObjectPool< T >:

Public Member Functions

 ObjectPool (uint_t size)
 Constructor. More...
 
virtual ~ObjectPool ()
 Destructor. More...
 
virtual T * reserve ()=0
 Reserve an object from the pool. More...
 
virtual void release (T *elem)=0
 Release an object back to the pool. More...
 
uint_t getSize () const
 Get the size of the pool, i.e., the total number of objects (both reserved and available) in the pool. More...
 
uint_t getAvailable () const
 Get the number of available (unreserved) objects in the pool. More...
 

Protected Attributes

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

Detailed Description

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

A base class for object pools.

See DynamicObjectPool and StaticObjectPool for concrete implementations.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ ObjectPool()

ObjectPool ( uint_t  size)
inline

Constructor.

Parameters
sizeThe number of objects to allocate in the pool.

◆ ~ObjectPool()

virtual ~ObjectPool ( )
inlinevirtual

Destructor.

Member Function Documentation

◆ getAvailable()

uint_t getAvailable ( ) const
inline

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

◆ getSize()

uint_t getSize ( ) const
inline

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

◆ release()

virtual void release ( T *  elem)
pure virtual

Release an object back to the pool.

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

Parameters
elemThe object to release.
Exceptions
ObjectPoolExceptionIf elem is NULL.

Implemented in DynamicObjectPool< T >, StaticObjectPool< T >, StaticObjectPool< ccxx::StreamSocket >, StaticObjectPool< _Datum >, and StaticObjectPool< _Node >.

◆ reserve()

virtual T* reserve ( )
pure virtual

Reserve an object from the pool.

Returns
The reserved object.
Exceptions
ObjectPoolExceptionIf no objects are available in the pool.

Implemented in DynamicObjectPool< T >, StaticObjectPool< T >, StaticObjectPool< ccxx::StreamSocket >, StaticObjectPool< _Datum >, and StaticObjectPool< _Node >.

Member Data Documentation

◆ _avail

uint_t _avail
protected

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

◆ _size

uint_t _size
protected

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: