-
template
class
ObjectPool<class Object>
(Return to index)
-
Support for keeping a "pool" of frequently-used objects, to avoidhaving to free and re-allocate them all the time.
Type:
Include file:
Synopsis:
Public methods:
- public typedef void
(*ObjectCallback) (Object * obj, void * userData)
- public Object *
GetObject ()
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 object can be used similarly
to the new operator.
- public
ObjectPool (uint32 maxPoolSize=100, ObjectCallback recycleCallback = NULL, void * recycleData = NULL, ObjectCallback initCallback = NULL, void * initData = NULL)
(maxPoolSize) is the maximum number of "standby" objects to keep around
for recycling at any given time.
- public void
ReleaseObject (Object * obj, uint32 numItems = 1)
Adds the given object to our "standby" object list to be recycled.
If our list is already at its maximum size, then (obj) will be deleted.
(obj) may be NULL. This method can be used similarly to the delete operator.
- public void
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.
If you need to do any initialization on the new Object, you can
do it here.
(userData) will be passed through to the callback function.
- public 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.
If you wish to do any cleanup on the object, you can do it here.
(userData) will be passed through to the callback function.
- public
~ObjectPool ()
Protected methods: