Class ObjectPool<T>
- Namespace
- RichHudFramework
- Assembly
- RichHudClient.dll
Simple, non-thread-safe object pool backed by a List<T>. Reduces allocations for frequently created/disposed reference types.
public class ObjectPool<T> where T : class
Type Parameters
T
- Inheritance
-
ObjectPool<T>
Constructors
ObjectPool(IPooledObjectPolicy<T>)
public ObjectPool(IPooledObjectPolicy<T> policy)
Parameters
policyIPooledObjectPolicy<T>
ObjectPool(Func<T>, Action<T>)
public ObjectPool(Func<T> getNewFunc, Action<T> resetFunc)
Parameters
Properties
Capacity
Internal pool capacity
public int Capacity { get; }
Property Value
Count
Number of objects currently stored in the pool
public int Count { get; }
Property Value
Methods
Clear()
public void Clear()
Get()
Retrieves an object from the pool. Returns a recycled instance if available; otherwise creates a new one using the policy.
public T Get()
Returns
- T
Return(T)
Returns a single object to the pool after resetting it.
public void Return(T obj)
Parameters
objT
ReturnRange(IReadOnlyList<T>, int, int)
Returns a range of objects to the pool
public void ReturnRange(IReadOnlyList<T> objects, int index = 0, int count = -1)
Parameters
objectsIReadOnlyList<T>indexintcountint
ReturnRange<T2>(IReadOnlyList<MyTuple<T, T2>>, int, int)
Returns a range of objects to the pool from a tuple list
public void ReturnRange<T2>(IReadOnlyList<MyTuple<T, T2>> objects, int index = 0, int count = -1)
Parameters
objectsIReadOnlyList<MyTuple<T, T2>>indexintcountint
Type Parameters
T2
TrimExcess()
public void TrimExcess()