Generic Pool to re-use objects of a certain type (TType) that optionally match a certain property or set of properties (TInfo). More...
Inherits IDisposable.
Public Member Functions | |
ObjectPool (int capacity, string name) | |
Create a new ObjectPool instance. Does not call Init(). More... | |
ObjectPool (int capacity, string name, TInfo info) | |
Create a new ObjectPool instance with the given info structure. Calls Init(). More... | |
void | Init (TInfo info) |
(Re-)Initializes this ObjectPool. More... | |
TType | AcquireOrCreate () |
Acquire an existing object, or create a new one if none are available. More... | |
TType | AcquireOrCreate (TInfo info) |
Acquire an existing object (if info matches), or create a new one from the passed info. More... | |
virtual bool | Release (TType obj, TInfo objInfo) |
Returns object to pool. More... | |
virtual bool | Release (TType obj) |
Returns object to pool, or destroys it if the pool is full. More... | |
void | Dispose () |
Free resources assoicated with this ObjectPool More... | |
Protected Member Functions | |
abstract TType | createObject (TInfo info) |
abstract void | destroyObject (TType obj) |
abstract bool | infosMatch (TInfo i0, TInfo i1) |
Protected Attributes | |
int | capacity |
TInfo | info |
int | pos |
string | name |
Properties | |
TInfo | Info [get] |
The property (info) that objects in this Pool must match. More... | |
Generic Pool to re-use objects of a certain type (TType) that optionally match a certain property or set of properties (TInfo).
TType | Object type. |
TInfo | Type of parameter used to check 2 objects identity (like integral length of array). |
ObjectPool | ( | int | capacity, |
string | name | ||
) |
Create a new ObjectPool instance. Does not call Init().
capacity | Capacity (size) of the object pool. |
name | Name of the object pool. |
ObjectPool | ( | int | capacity, |
string | name, | ||
TInfo | info | ||
) |
Create a new ObjectPool instance with the given info structure. Calls Init().
capacity | Capacity (size) of the object pool. |
name | Name of the object pool. |
info | Info about this Pool's objects. |
TType AcquireOrCreate | ( | ) |
Acquire an existing object, or create a new one if none are available.
If it fails to get one from the pool, this will create from the info given in this pool's constructor.
TType AcquireOrCreate | ( | TInfo | info | ) |
Acquire an existing object (if info matches), or create a new one from the passed info.
info | Info structure to match, or create a new object with. |
void Dispose | ( | ) |
Free resources assoicated with this ObjectPool
void Init | ( | TInfo | info | ) |
(Re-)Initializes this ObjectPool.
If there are objects available in this Pool, they will be destroyed. Allocates (Capacity) new Objects.
info | Info about this Pool's objects. |
|
virtual |
Returns object to pool, or destroys it if the pool is full.
obj | The object to return to the pool. |
|
virtual |
Returns object to pool.
obj | The object to return to the pool. |
objInfo | The info structure about obj. |
obj is returned to the pool only if objInfo matches this pool's info. Else, it is destroyed.
|
get |
The property (info) that objects in this Pool must match.