libcommonc++  0.7
DynamicObjectPool< T > Class Template Reference

An object pool that dynamically allocates its objects. More...

#include <DynamicObjectPool.h++>

Inheritance diagram for DynamicObjectPool< T >:
Collaboration diagram for DynamicObjectPool< T >:

Public Member Functions

 DynamicObjectPool (uint_t size, void(*resetFunc)(T *), bool lazy=false)
 Construct a new DynamicObjectPool of the given size. More...
 
 ~DynamicObjectPool ()
 Destructor. More...
 
T * reserve ()
 Reserve an object from the pool. More...
 
void release (T *elem)
 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<class T>
class ccxx::DynamicObjectPool< T >

An object pool that dynamically allocates its objects.

DynamicObjectPool allocates objects on the heap, either all at once when the pool is constructed, or on an as-needed basis, up to the specified limit.

The template parameter T must be a class which has a default constructor. This constructor is used to create new instances of the object.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ DynamicObjectPool()

DynamicObjectPool ( uint_t  size,
void(*)(T *)  resetFunc,
bool  lazy = false 
)

Construct a new DynamicObjectPool of the given size.

Parameters
sizeThe maximum number of objects to allocate in the pool.
resetFuncA function that will be used to "reset" objects to their initial state when they are returned to the pool.
lazyA flag indicating whether objects will be allocated as needed or initially all at once.

◆ ~DynamicObjectPool()

Destructor.

Deletes all of the objects managed the pool, whether or not they are reserved.

Member Function Documentation

◆ getAvailable()

uint_t getAvailable ( ) const
inlineinherited

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

◆ getSize()

uint_t getSize ( ) const
inlineinherited

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

◆ release()

void release ( T *  elem)
virtual

Release an object back to the pool.

The object's reset member function is called before the object is released back to the pool.

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

Implements ObjectPool< T >.

◆ reserve()

T* reserve ( )
virtual

Reserve an object from the pool.

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

Implements ObjectPool< T >.

Member Data Documentation

◆ _avail

uint_t _avail
protectedinherited

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

◆ _size

uint_t _size
protectedinherited

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: