Class ObjectPool<T>
Represent a pool of objects.
public abstract class ObjectPool<T>
Type Parameters
TType of object to pool.
- Inheritance
-
ObjectPool<T>
- Derived
- Inherited Members
Constructors
ObjectPool()
protected ObjectPool()
Methods
ApproximateCount()
Gets an approximate count of the objects stored in the pool.
This value is not accurate and may be lower or higher than the actual count.
This is primarily used for debugging purposes.
public abstract int ApproximateCount()
Returns
- int
Approximate count of elements in the pool. If this operation is not supported, return
-1instead of throwing.
Rent()
Rent an element from the pool.
If the pool is empty, instantiate a new element.
Implementors of this class can choose how elements are instantiated and initialized, or throw if instantiation of new elements is not supported.
public abstract T Rent()
Returns
- T
Rented element.
RentLease()
Rent an element from the pool.
If the pool is empty, instantiate a new element.
Implementors of this class can choose how elements are instantiated and initialized, or throw if instantiation of new elements is not supported.
public Lease<T> RentLease()
Returns
- Lease<T>
A contained of the rented element. When this container is disposed, the object will be returned to the pool.
Return(T)
Return an element to the pool.
If the pool is full, it's an implementation detail whenever the object is free or the pool is resized.
If element is default, it's an implementation detail whenever it throws an exception or ignores the call. However, it should never leave the pool in an invalid state.
public abstract void Return(T element)
Parameters
elementTElement to return.
Trim(bool)
Trim the content of the pool.
public abstract void Trim(bool force = false)
Parameters
forceboolIf true, the pool is forced to clear all elements inside. Otherwise, the pool may only clear partially or not clear at all if the heuristic says so.