Curvy  8.3.0
ArrayPool< T > Class Template Reference
+ Collaboration diagram for ArrayPool< T >:

Detailed Description

A pool of allowing the re-usage of previously allocated and discarded arrays. Helps reducing garbage collection.

Is thread safe

See also
SubArray<T>

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

Constructor & Destructor Documentation

ArrayPool ( long  elementsCapacity)

Creates a new pool

Parameters
elementsCapacityElementsCapacity

Member Function Documentation

SubArray<T> Allocate ( int  minimalSize,
bool  clearArray = true 
)

Allocates a new array if none available, or reuses an existing one otherwise

Parameters
minimalSizeThe array's guaranteed minimal size
clearArrayWhether the returned array's elements will be guaranteed to be set to their default value
Returns
SubArray<T> AllocateExactSize ( int  exactSize,
bool  clearArray = true 
)

Allocates a new array if none available, or reuses an existing one otherwise

Parameters
exactSizeThe array's exact size
clearArrayWhether the returned array's elements will be guaranteed to be set to their default value
Returns
SubArray<T> Clone ( T[]  source)

Return a new SubArray<T> instance that will use a copy of the given input array

SubArray<T> Clone ( SubArray< T >  source)

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

Parameters
subArrayThe array to resize
newMinimalSizeThe new size
clearNewSpaceWhen 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

Member Data Documentation

ArrayPoolUsageData UsageData => new ArrayPoolUsageData(elementsCount, arraysCount, elementsCapacity)

Returns data about the pool's usage.

ArrayPoolUsageData

Property Documentation

long ElementsCapacity
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

bool LogAllocations
getset

Log in the console each time a new array is allocated in memory


The documentation for this class was generated from the following file: