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
Fields
4 private and internal fields
| Member | What it is |
|---|
private readonly ConcurrentBag<T[]>[] buckets | One bag of free arrays per power-of-two size from 16 upwards. |
private static T[] empty | Empty array returned for size 0 requests. |
private static readonly Logger Logger | Class logger, used for null or wrong-sized releases. |
private static UnclearedPower2ArrayPool<T> shared | Backing field for Shared. |
Properties
| Member | What 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
| Member | What it is |
|---|
private IEnumerable<Array>[] Alta.ArrayPools.IUnclearedPower2ArrayPool.Buckets { get; } | The pooled arrays per size bucket, exposed to ArrayPoolManager. |
Methods
| Member | What 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<T>: