KS.Reactor.ksObjectPool< T > Class Template Reference

Static class for configuring object pools. More...

Public Member Functions

delegate T Factory ()
 Creates a new instance for the pool. More...
 
 ksObjectPool ()
 Constructor that uses the default constructor to create T instances. More...
 
 ksObjectPool (Factory factory, int limit=-1)
 Constructor that uses a factory More...
 
void Create (int amount)
 Creates new objects and add them to the pool. More...
 
AtomicFetch ()
 Fetch an instance of the object from the pool thread-safely. More...
 
Fetch ()
 Fetch an instance of the object from the pool. More...
 
void AtomicReturn (T obj)
 Returns an object to the pool thread-safely. More...
 
void Return (T obj)
 Returns an object to the pool. More...
 

Static Public Attributes

static int DefaultLimit = 0
 The default maximum number of objects to allow in objects pools. More...
 

Properties

static ksObjectPool< T > Instance [get]
 Static instance. More...
 
int? Limit [get]
 The maximum number of objects allowed in the pool. More...
 
int OverrideLimit [get, set]
 If this is greater than or equal to zero, this is used as the Limit instead of ksObjectPool.DefaultLimit. More...
 
bool IsFull [get]
 Has the pool size reached the Limit? More...
 

Detailed Description

Static class for configuring object pools.

An object pool that constructs new objects using the default constructor or a factory delegate.

Template Parameters
TType of object in the pool
Type Constraints
T :class 

Constructor & Destructor Documentation

◆ ksObjectPool() [1/2]

Constructor that uses the default constructor to create T instances.

◆ ksObjectPool() [2/2]

KS.Reactor.ksObjectPool< T >.ksObjectPool ( Factory  factory,
int  limit = -1 
)

Constructor that uses a factory

Parameters
factoryFactory to create new instances.
limitMaximum number of objects allowed in the pool. If less than zero, use ksObjectPool.DefaultLimit

Member Function Documentation

◆ AtomicFetch()

T KS.Reactor.ksObjectPool< T >.AtomicFetch ( )

Fetch an instance of the object from the pool thread-safely.

If the pool is empty, then create a new object.

Returns
instance

◆ AtomicReturn()

void KS.Reactor.ksObjectPool< T >.AtomicReturn ( obj)

Returns an object to the pool thread-safely.

Parameters
objPool object.

◆ Create()

void KS.Reactor.ksObjectPool< T >.Create ( int  amount)

Creates new objects and add them to the pool.

Parameters
amountAmount of objects to create.

◆ Factory()

delegate T KS.Reactor.ksObjectPool< T >.Factory ( )

Creates a new instance for the pool.

Returns
new instance

◆ Fetch()

T KS.Reactor.ksObjectPool< T >.Fetch ( )

Fetch an instance of the object from the pool.

If the pool is empty, then create a new object.

Returns

◆ Return()

void KS.Reactor.ksObjectPool< T >.Return ( obj)

Returns an object to the pool.

Objects will not be returned if the pool IsFull.

Parameters
objPool object.

Member Data Documentation

◆ DefaultLimit

int KS.Reactor.ksObjectPool< T >.DefaultLimit = 0
static

The default maximum number of objects to allow in objects pools.

Object pools that have a negative ksObjectPool<T>.OverrideLimit will use this value. By default this is zero which disables object pooling. If you enable object pooling, be aware that entities and linear predictors will be pooled, so references to destroyed entities can become references to new entities, and linear predictors cannot be reassigned once they are unassigned and returned to the pool.

Property Documentation

◆ Instance

ksObjectPool<T> KS.Reactor.ksObjectPool< T >.Instance
staticget

Static instance.

◆ IsFull

bool KS.Reactor.ksObjectPool< T >.IsFull
get

Has the pool size reached the Limit?

◆ Limit

int? KS.Reactor.ksObjectPool< T >.Limit
get

The maximum number of objects allowed in the pool.

Returns OverrideLimit if it is greater than or equal to zero, otherwise returns ksObjectPool.DefaultLimit.

◆ OverrideLimit

int KS.Reactor.ksObjectPool< T >.OverrideLimit
getset

If this is greater than or equal to zero, this is used as the Limit instead of ksObjectPool.DefaultLimit.