|
LPCGame
A 2d game 'engine' written in C++
|
An object pool. More...
#include <objectpool.h>
Public Member Functions | |
| ObjectPool (size_t chunkSize=kDefaultChunkSize) throw (std::invalid_argument, std::bad_alloc) | |
| std::shared_ptr< T > | AcquireObject () |
| void | ReturnObject (std::shared_ptr< T > obj) |
Protected Member Functions | |
| void | AllocateChunk () |
| Allocate mChunkSize objects for the pool to use. | |
Protected Attributes | |
| std::queue< std::shared_ptr< T > > | mFreeList |
| The list of objects not currently in use. | |
| size_t | mChunkSize |
Static Protected Attributes | |
| static const size_t | kDefaultChunkSize = 10 |
An object pool.
An object pool where users can request objects, run them, and return them too the pool
| ObjectPool< T >::ObjectPool | ( | size_t | chunkSize = kDefaultChunkSize | ) | throw (std::invalid_argument, std::bad_alloc) |
Initialize an object pool with chunkSize objects
| invalid_argument | if chunksize is 0 |
| bad_alloc | if allocation fails |
| std::shared_ptr< T > ObjectPool< T >::AcquireObject | ( | ) |
Reserve an object for use Note: Users must NOT free the object
|
protected |
Allocate mChunkSize objects for the pool to use.
| void ObjectPool< T >::ReturnObject | ( | std::shared_ptr< T > | obj | ) |
Return an object to the pool Note: Users must NOT use the object after returning
| obj | The object to return to the pool |
|
staticprotected |
|
protected |
|
protected |
The list of objects not currently in use.