Skip to main content

UnclearedPower2ArrayPool<T>

A class in Alta.ArrayPools.Runtime, Alta.ArrayPools.

Thread-safe pool of arrays in power-of-two sizes (16 and up). Arrays are not cleared, so a requested array can be larger than asked for and hold old data. Use Shared for the common pool.

Constructors​

MemberWhat it is
UnclearedPower2ArrayPool()Creates an UnclearedPower2ArrayPool with default values.

Fields​

4 private and internal fields
MemberWhat it is
private readonly ConcurrentBag<T[]>[] bucketsOne bag of free arrays per power-of-two size from 16 upwards.
private static T[] emptyEmpty array returned for size 0 requests.
private static readonly Logger LoggerClass logger, used for null or wrong-sized releases.
private static UnclearedPower2ArrayPool<T> sharedBacking field for Shared.

Properties​

MemberWhat it is
int CurrentlyRequestedArrays { get; private set; }Requests minus releases so far, for spotting arrays that were never returned.
static UnclearedPower2ArrayPool<T> Shared { get; }The shared pool for this element type, created on first use.
1 private and internal property
MemberWhat it is
private IEnumerable<Array>[] Alta.ArrayPools.IUnclearedPower2ArrayPool.Buckets { get; }The pooled arrays per size bucket, exposed to ArrayPoolManager.

Methods​

MemberWhat it is
T[] Copy(T[] sourceArray)Requests a pooled array and copies the source into it. Null gives null.
void Release(T[] array)Returns an array to its size bucket. Logs a fatal error for a non power-of-two length but still pools it.
T[] Request(int size)Gets an array of at least the given size, rounded up to a power of two (minimum 16). Size 0 or less gives an empty array.
T[] ToArray(List<T> list)Copies a list into a pooled array. The array may be longer than the list.

Used in​

Members of other types that take, return or hold a UnclearedPower2ArrayPool&lt;T>: