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... | |
T | AtomicFetch () |
Fetch an instance of the object from the pool thread-safely. More... | |
T | 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... | |
Static class for configuring object pools.
An object pool that constructs new objects using the default constructor or a factory delegate.
T | Type of object in the pool |
T | : | class |
KS.Reactor.ksObjectPool< T >.ksObjectPool | ( | ) |
Constructor that uses the default constructor to create T instances.
KS.Reactor.ksObjectPool< T >.ksObjectPool | ( | Factory | factory, |
int | limit = -1 |
||
) |
Constructor that uses a factory
factory | Factory to create new instances. |
limit | Maximum number of objects allowed in the pool. If less than zero, use ksObjectPool.DefaultLimit |
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.
void KS.Reactor.ksObjectPool< T >.AtomicReturn | ( | T | obj | ) |
Returns an object to the pool thread-safely.
obj | Pool object. |
void KS.Reactor.ksObjectPool< T >.Create | ( | int | amount | ) |
Creates new objects and add them to the pool.
amount | Amount of objects to create. |
delegate T KS.Reactor.ksObjectPool< T >.Factory | ( | ) |
Creates a new instance for the pool.
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.
void KS.Reactor.ksObjectPool< T >.Return | ( | T | obj | ) |
Returns an object to the pool.
Objects will not be returned if the pool IsFull.
obj | Pool object. |
|
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.
|
staticget |
Static instance.
|
get |
Has the pool size reached the 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.
|
getset |
If this is greater than or equal to zero, this is used as the Limit instead of ksObjectPool.DefaultLimit.