Photon Voice v2.53

Public Member Functions | Protected Member Functions | Protected Attributes | Properties | List of all members
ObjectPool< TType, TInfo > Class Template Referenceabstract

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...
 

Detailed Description

Generic Pool to re-use objects of a certain type (TType) that optionally match a certain property or set of properties (TInfo).

Template Parameters
TTypeObject type.
TInfoType of parameter used to check 2 objects identity (like integral length of array).

Constructor & Destructor Documentation

◆ ObjectPool() [1/2]

ObjectPool ( int  capacity,
string  name 
)

Create a new ObjectPool instance. Does not call Init().

Parameters
capacityCapacity (size) of the object pool.
nameName of the object pool.

◆ ObjectPool() [2/2]

ObjectPool ( int  capacity,
string  name,
TInfo  info 
)

Create a new ObjectPool instance with the given info structure. Calls Init().

Parameters
capacityCapacity (size) of the object pool.
nameName of the object pool.
infoInfo about this Pool's objects.

Member Function Documentation

◆ AcquireOrCreate() [1/2]

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.

◆ AcquireOrCreate() [2/2]

TType AcquireOrCreate ( TInfo  info)

Acquire an existing object (if info matches), or create a new one from the passed info.

Parameters
infoInfo structure to match, or create a new object with.

◆ Dispose()

void Dispose ( )

Free resources assoicated with this ObjectPool

◆ Init()

void Init ( TInfo  info)

(Re-)Initializes this ObjectPool.

If there are objects available in this Pool, they will be destroyed. Allocates (Capacity) new Objects.

Parameters
infoInfo about this Pool's objects.

◆ Release() [1/2]

virtual bool Release ( TType  obj)
virtual

Returns object to pool, or destroys it if the pool is full.

Parameters
objThe object to return to the pool.

◆ Release() [2/2]

virtual bool Release ( TType  obj,
TInfo  objInfo 
)
virtual

Returns object to pool.

Parameters
objThe object to return to the pool.
objInfoThe info structure about obj.

obj is returned to the pool only if objInfo matches this pool's info. Else, it is destroyed.

Property Documentation

◆ Info

TInfo Info
get

The property (info) that objects in this Pool must match.