ObjectPool<T>
Class in Zigurous.DataStructures
Implements IObjectPool<T>, IDisposable
Declaration
public sealed class ObjectPool<T> : IObjectPool<T> where T : classDescription
Reuses objects from a shared pool to prevent instantiating new objects. The object pool can have a set capacity or it can grow in size. Optionally, objects that are currently active can be reused when the pool has reached capacity.
Type Parameters
| T | The type of object to pool. |
Properties
| pool | The list of all objects waiting to be reused (Read only). |
| activeItems | The list of objects currently being used (Read only). |
| activeCount | The number of objects currently being used (Read only). |
| availableCount | The number of objects available to be reused (Read only). |
| maxCapacity | The maximum number of objects that can be generated. |
| reuseActive | Whether active objects should be reused when the object pool has reached capacity. |
| generator | The function that generates a new object. |
Constructors
| ObjectPool | Creates a new object pool with an initial capacity. New objects are created as needed using the object type default value. |
Methods
| Dispose | Disposes of all class resources. |
| Retrieve | Removes and returns an object from the pool. If there are no available objects in the pool, either a new object will be generated or the oldest object will be reused depending upon how the object pool is configured. |
| Recycle | Adds an object back to the pool so it can be reused. |
| Empty | Empties the pool of all objects. |