libcommonc++
0.7
|
An object pool that allocates (presumably fixed-size) objects in a contiguous memory buffer. More...
#include <StaticObjectPool.h++>
Public Member Functions | |
StaticObjectPool (uint_t size) | |
Construct a new StaticObjectPool of the given size. More... | |
~StaticObjectPool () | |
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... | |
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.
StaticObjectPool | ( | uint_t | size | ) |
Construct a new StaticObjectPool of the given size.
size | The number of objects to allocate in the pool. |
~StaticObjectPool | ( | ) |
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.
|
inlineinherited |
Get the number of available (unreserved) objects in the pool.
|
inlineinherited |
Get the size of the pool, i.e., the total number of objects (both reserved and available) in the pool.
|
virtual |
Release an object back to the pool.
The object's destructor is called before the object is released back to the pool.
elem | The object to release. |
ObjectPoolException | If elem is NULL. |
Implements ObjectPool< T >.
|
virtual |
Reserve an object from the pool.
The object's constructor is called before the object is returned.
ObjectPoolException | If there are no more objects available in the pool. |
Implements ObjectPool< T >.
|
protectedinherited |
The number of objects currently available (not reserved) in the pool.
|
protectedinherited |
The size of the pool (i.e., the maximum number of objects managed by the pool).