Table of Contents

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

policy IPooledObjectPolicy<T>

ObjectPool(Func<T>, Action<T>)

public ObjectPool(Func<T> getNewFunc, Action<T> resetFunc)

Parameters

getNewFunc Func<T>
resetFunc Action<T>

Properties

Capacity

Internal pool capacity

public int Capacity { get; }

Property Value

int

Count

Number of objects currently stored in the pool

public int Count { get; }

Property Value

int

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

obj T

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

objects IReadOnlyList<T>
index int
count int

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

objects IReadOnlyList<MyTuple<T, T2>>
index int
count int

Type Parameters

T2

TrimExcess()

public void TrimExcess()