#include <ObjectPool.h>
Inheritance diagram for ObjectPool< Object >:

Public Types | |
| typedef void(*) | ObjectCallback (Object *obj, void *userData) |
| Callback function type for Init and Recycle callbacks. | |
Public Member Functions | |
| ObjectPool (uint32 maxPoolSize=100, ObjectCallback recycleCallback=NULL, void *recycleData=NULL, ObjectCallback initCallback=NULL, void *initCallbackData=NULL) | |
| Constructor. | |
| virtual | ~ObjectPool () |
| Destructor. | |
| Object * | ObtainObject () |
| Returns a new Object for use (or NULL if no memory available). | |
| void | ReleaseObject (Object *obj) |
| Adds the given object to our "standby" object list to be recycled, or deletes it if the "standby" list is already at its maximum size. | |
| virtual void * | ObtainObjectGeneric () |
| AbstractObjectGenerator API: Useful for polymorphism. | |
| virtual void | RecycleObject (void *obj) |
| AbstractObjectRecycler API: Useful for polymorphism. | |
| status_t | SetInitObjectCallback (ObjectCallback cb, void *userData) |
| With this call you can specify a callback function that will be called whenever a new Object is created by this pool. | |
| void | SetRecycleObjectCallback (ObjectCallback cb, void *userData) |
| With this call you can specify a callback function that will be called by ReleaseObject() whenever it is putting an Object into its standby list. | |
| virtual uint32 | FlushCachedObjects () |
| Implemented to call Drain() and return the number of objects drained. | |
| status_t | Drain (uint32 *optSetNumDrained=NULL) |
| Removes all "spare" objects from the pool and deletes them. | |
| uint32 | GetMaxPoolSize () const |
| Returns the maximum number of "spare" objects that will be kept in the pool, ready to be recycled. | |
| void | SetMaxPoolSize (uint32 mps) |
| Sets a new maximum size for this pool. | |
Friends | |
| class | ObjectSlab |
Classes | |
| class | ObjectNode |
| class | ObjectSlab |
Instead of calling 'new Object', you call myObjectPool.ObtainObject(), and instead of calling 'delete Object', you call myObjectPool.ReleaseObject(). The advantage is that the ObjectPool will keep (up to) a certain number of "spare" Objects around, and recycle them back to you as needed.
Definition at line 92 of file ObjectPool.h.
| ObjectPool< Object >::ObjectPool | ( | uint32 | maxPoolSize = 100, |
|
| ObjectCallback | recycleCallback = NULL, |
|||
| void * | recycleData = NULL, |
|||
| ObjectCallback | initCallback = NULL, |
|||
| void * | initCallbackData = NULL | |||
| ) | [inline] |
Constructor.
| maxPoolSize | the maximum number of recycled objects that may be kept around for future reuse at any one time. | |
| recycleCallback | optional callback function to be called whenever an object is returned to the pool. | |
| recycleData | user value to be passed in to the recycleCallback function. | |
| initCallback | optional callback function to be called whenever an object is taken out of the pool. | |
| initCallbackData | user value to be passed in to the initCallback function. |
Definition at line 106 of file ObjectPool.h.
| virtual ObjectPool< Object >::~ObjectPool | ( | ) | [inline, virtual] |
Destructor.
Deletes all objects in the pool.
Definition at line 119 of file ObjectPool.h.
References ObjectPool< Object >::ObjectSlab.
| Object* ObjectPool< Object >::ObtainObject | ( | ) | [inline] |
Returns a new Object for use (or NULL if no memory available).
You are responsible for calling ReleaseObject() on this object when you are done with it. This method is thread-safe.
Definition at line 140 of file ObjectPool.h.
References Mutex::Lock(), ObjectPool< Object >::ObjectSlab, and Mutex::Unlock().
Referenced by ObjectPool< Object >::ObtainObjectGeneric().
| void ObjectPool< Object >::ReleaseObject | ( | Object * | obj | ) | [inline] |
Adds the given object to our "standby" object list to be recycled, or deletes it if the "standby" list is already at its maximum size.
This method is thread-safe.
| obj | An Object to recycle or delete. May be NULL. |
Definition at line 197 of file ObjectPool.h.
References Mutex::Lock(), ObjectPool< Object >::ObjectSlab, and Mutex::Unlock().
Referenced by ObjectPool< Object >::RecycleObject().
| status_t ObjectPool< Object >::SetInitObjectCallback | ( | ObjectCallback | cb, | |
| void * | userData | |||
| ) | [inline] |
With this call you can specify a callback function that will be called whenever a new Object is created by this pool.
If you need to do any initialization on the new Object, you can do it here. This method is thread safe.
| cb | The callback function that ObtainObject() will call. | |
| userData | User value that will be passed through to the callback function. |
Definition at line 252 of file ObjectPool.h.
References Mutex::Lock(), and Mutex::Unlock().
| void ObjectPool< Object >::SetRecycleObjectCallback | ( | ObjectCallback | cb, | |
| void * | userData | |||
| ) | [inline] |
With this call you can specify a callback function that will be called by ReleaseObject() whenever it is putting an Object into its standby list.
If you wish to do any cleanup on the object, you can do it here.
| cb | The callback function that ReleaseObject() will call. | |
| userData | User value that will be passed through to the callback function. |
Definition at line 273 of file ObjectPool.h.
References Mutex::Lock(), and Mutex::Unlock().
| status_t ObjectPool< Object >::Drain | ( | uint32 * | optSetNumDrained = NULL |
) | [inline] |
Removes all "spare" objects from the pool and deletes them.
This method is thread-safe.
| optSetNumDrained | If non-NULL, this value will be set to the number of objects destroyed. |
Definition at line 293 of file ObjectPool.h.
References Mutex::Lock(), ObjectPool< Object >::ObjectSlab, and Mutex::Unlock().
Referenced by ObjectPool< Object >::FlushCachedObjects().
| uint32 ObjectPool< Object >::GetMaxPoolSize | ( | ) | const [inline] |
Returns the maximum number of "spare" objects that will be kept in the pool, ready to be recycled.
This is the value that was previously set either in the constructor or by SetMaxPoolSize().
Definition at line 338 of file ObjectPool.h.
| void ObjectPool< Object >::SetMaxPoolSize | ( | uint32 | mps | ) | [inline] |
Sets a new maximum size for this pool.
Note that changing this value will not cause any object to be added or removed to the pool immediately; rather the new size will be enforced only on future operations.
Definition at line 345 of file ObjectPool.h.
1.5.1