A pool of allowing the re-usage of previously allocated and discarded arrays. Helps reducing garbage collection.
Is thread safe
Public Attributes | |
ArrayPoolUsageData | UsageData => new ArrayPoolUsageData(elementsCount, arraysCount, elementsCapacity) |
Returns data about the pool's usage. More... | |
Properties | |
long | ElementsCapacity [get, set] |
The maximal number of elements that the pool will keep, after they have been freed, to be available for future usage. Once this limit is reached, every freed array will simply get ignored, allowing the garbage collector to collect it More... | |
bool | LogAllocations [get, set] |
Log in the console each time a new array is allocated in memory More... | |
Public Member Functions | |
SubArray< T > | Allocate (int minimalSize, bool clearArray=true) |
Allocates a new array if none available, or reuses an existing one otherwise More... | |
SubArray< T > | AllocateExactSize (int exactSize, bool clearArray=true) |
Allocates a new array if none available, or reuses an existing one otherwise More... | |
ArrayPool (long elementsCapacity) | |
Creates a new pool More... | |
SubArray< T > | Clone (T[] source) |
Return a new SubArray<T> instance that will use a copy of the given input array More... | |
SubArray< T > | Clone (SubArray< T > source) |
Return a new SubArray<T> instance that will use a copy of the given input array More... | |
void | Free (SubArray< T > subArray) |
Returns an array to the pool, ready to be reused More... | |
void | Free (T[] array) |
Returns an array to the pool, ready to be reused More... | |
void | Resize (ref SubArray< T > subArray, int newMinimalSize, bool clearNewSpace=true) |
Resizes the given array More... | |
void | ResizeAndClear (ref SubArray< T > subArray, int newMinimalSize) |
Resize an array to a new size and clears it. Similar to calling Free(ToolBuddy.Pooling.Collections.SubArray<T>) then calling Allocate, but done in a more optimized way More... | |
ArrayPool | ( | long | elementsCapacity | ) |
Creates a new pool
elementsCapacity | ElementsCapacity |
SubArray<T> Allocate | ( | int | minimalSize, |
bool | clearArray = true |
||
) |
Allocates a new array if none available, or reuses an existing one otherwise
minimalSize | The array's guaranteed minimal size |
clearArray | Whether the returned array's elements will be guaranteed to be set to their default value |
SubArray<T> AllocateExactSize | ( | int | exactSize, |
bool | clearArray = true |
||
) |
Allocates a new array if none available, or reuses an existing one otherwise
exactSize | The array's exact size |
clearArray | Whether the returned array's elements will be guaranteed to be set to their default value |
SubArray<T> Clone | ( | T[] | source | ) |
Return a new SubArray<T> instance that will use a copy of the given input array
Return a new SubArray<T> instance that will use a copy of the given input array
void Free | ( | SubArray< T > | subArray | ) |
Returns an array to the pool, ready to be reused
void Free | ( | T[] | array | ) |
Returns an array to the pool, ready to be reused
void Resize | ( | ref SubArray< T > | subArray, |
int | newMinimalSize, | ||
bool | clearNewSpace = true |
||
) |
Resizes the given array
subArray | The array to resize |
newMinimalSize | The new size |
clearNewSpace | When resizing and array to make it bigger, should the newly available space be cleared or not. |
void ResizeAndClear | ( | ref SubArray< T > | subArray, |
int | newMinimalSize | ||
) |
Resize an array to a new size and clears it. Similar to calling Free(ToolBuddy.Pooling.Collections.SubArray<T>) then calling Allocate, but done in a more optimized way
ArrayPoolUsageData UsageData => new ArrayPoolUsageData(elementsCount, arraysCount, elementsCapacity) |
Returns data about the pool's usage.
|
getset |
The maximal number of elements that the pool will keep, after they have been freed, to be available for future usage. Once this limit is reached, every freed array will simply get ignored, allowing the garbage collector to collect it
This is not the maximal number of arrays, but the maximal sum of the arrays' lengths
|
getset |
Log in the console each time a new array is allocated in memory