#include <ObjectPool.h>
Public Member Functions | |
shared_ptr< T > | get () |
Gets an object from the pool. | |
void | clear () |
Releases all unused objects. | |
unsigned int | poolSize () const |
Returns the number of elements in the Pool Not thread safe - should be used as an indication only! | |
void | resize (unsigned int n) |
Ensures there are at least n objects in the pool. | |
Private Member Functions | |
shared_ptr< T > | wrap (T *ptr) |
Wraps a ptr with an appropriate shared_ptr. | |
T * | create () |
Creates a T. | |
Private Attributes | |
list< T * > | pool |
The pool of unused objects. | |
mutex | poolMutex |
Used to lock access to the pool. | |
Friends | |
class | ObjectPoolDeleter< T > |
The custom deleter class. |
It requires that its type, T is default constructible and has a reset() method. It will maintain a list of created but unused objects then return shared_ptr to them when asked. If there are no objects, then it will create one. All the nothrow guarentees are based on the default constructor and reset methods not throwing.
The ObjectPool must outlive all the objects that it is used to create. It is probably best if it is statically created!
This class is thread-safe.
Definition at line 32 of file ObjectPool.h.
|
Releases all unused objects. Note that objects currently in use will still be returned to the pool
|
|
Creates a T.
|
|
Gets an object from the pool. Will call reset on the object first
Referenced by SctData::ErfcFitObject::create(). |
|
Returns the number of elements in the Pool Not thread safe - should be used as an indication only!
|
|
Ensures there are at least n objects in the pool.
|
|
Wraps a ptr with an appropriate shared_ptr.
|
|
The custom deleter class.
Definition at line 73 of file ObjectPool.h. |
|
The pool of unused objects.
Definition at line 74 of file ObjectPool.h. |
|
Used to lock access to the pool.
Definition at line 75 of file ObjectPool.h. |