Table of Contents

Class SafeExactLengthArrayPool<T>

Namespace
Enderlook.Pools
Assembly
Enderlook.Pools.dll

A fast, dynamically-sized and thread-safe array pool to store arrays of specific lengths.

public sealed class SafeExactLengthArrayPool<T> : ExactLengthArrayPool<T>

Type Parameters

T

Type of element array to pool.

Inheritance
SafeExactLengthArrayPool<T>
Inherited Members

Constructors

SafeExactLengthArrayPool()

Creates a new instance of the pool.

public SafeExactLengthArrayPool()

Properties

Capacity

Capacity of the pool.
This region of the pool support concurrent access.
The capacity should preferably be not greater than ProcessorCount * 2, since it's fully iterated before accessing the reserve.

public int Capacity { get; init; }

Property Value

int

Exceptions

ArgumentOutOfRangeException

Throw when value is lower than 1.

IsReserveFixed

Determines if the reserve pool is not to grow nor shrink given its usage.

public bool IsReserveFixed { get; init; }

Property Value

bool

Reserve

Current capacity of the reserve.
This reserve pool is only acceded when the non-reserve capacity gets full or empty.
This is because this region can only be acceded by a single thread
This pool has a dynamic size so this value represent the initial size of the pool which may enlarge or shrink over time.

public int Reserve { get; init; }

Property Value

int

Exceptions

ArgumentOutOfRangeException

Throw when value is negative.

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 override int ApproximateCount()

Returns

int

Approximate count of elements in the pool. If this operation is not supported, return -1 instead of throwing.

OfLength(int, bool)

Gives the internal SafeExactLengthArrayObjectPool<T> that uses the current instance to create arrays of the specified length.

public override SafeExactLengthArrayObjectPool<T> OfLength(int length, bool clearArrayOnReturn = false)

Parameters

length int

Length of arrays.

clearArrayOnReturn bool

If this is true, buffers that will be stored to enable subsequent reuse in Return(T), will have their content cleared so that a subsequent consumer will not see the previous consumer's content.
If false or if the pool will release the buffer, the array's contents are left unchanged.

Returns

SafeExactLengthArrayObjectPool<T>

Wrapper of pool.

Rent(int)

public override T[] Rent(int length)

Parameters

length int

Returns

T[]

Return(T[], bool)

public override void Return(T[] array, bool clearArray = false)

Parameters

array T[]
clearArray bool

Trim(bool)

Trim the content of the pool.

public override void Trim(bool force = false)

Parameters

force bool

If 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.