3rd Eye Scene C#
3rd Eye Scene C# documentation
|
Provides a resource pool that enables reusing instances of type T:T[]. More...
Public Member Functions | |
abstract T[] | Rent (int minimumLength) |
Retrieves a buffer that is at least the requested length. | |
abstract void | Return (T[] array, bool clearArray=false) |
Returns to the pool an array that was previously obtained via Rent on the same ArrayPool{T} instance. | |
Static Public Member Functions | |
static ArrayPool< T > | Create () |
Creates a new ArrayPool{T} instance using default configuration options. | |
static ArrayPool< T > | Create (int maxArrayLength, int maxArraysPerBucket) |
Creates a new ArrayPool{T} instance using custom configuration options. | |
Properties | |
static ArrayPool< T > | Shared [get] |
Retrieves a shared ArrayPool{T} instance. |
Provides a resource pool that enables reusing instances of type T:T[].
Renting and returning buffers with an ArrayPool{T} can increase performance in situations where arrays are created and destroyed frequently, resulting in significant memory pressure on the garbage collector.
This class is thread-safe. All members may be used by multiple threads concurrently.
static ArrayPool<T> Tes::Buffers::ArrayPool< T >::Create | ( | ) | [inline, static] |
Creates a new ArrayPool{T} instance using default configuration options.
static ArrayPool<T> Tes::Buffers::ArrayPool< T >::Create | ( | int | maxArrayLength, |
int | maxArraysPerBucket | ||
) | [inline, static] |
Creates a new ArrayPool{T} instance using custom configuration options.
maxArrayLength | The maximum length of array instances that may be stored in the pool. |
maxArraysPerBucket | The maximum number of array instances that may be stored in each bucket in the pool. The pool groups arrays of similar lengths into buckets for faster access. |
The created pool will group arrays into buckets, with no more than maxArraysPerBucket in each bucket and with those arrays not exceeding maxArrayLength in length.
abstract T [] Tes::Buffers::ArrayPool< T >::Rent | ( | int | minimumLength | ) | [pure virtual] |
Retrieves a buffer that is at least the requested length.
minimumLength | The minimum length of the array needed. |
This buffer is loaned to the caller and should be returned to the same pool via Return so that it may be reused in subsequent usage of Rent. It is not a fatal error to not return a rented buffer, but failure to do so may lead to decreased application performance, as the pool may need to create a new buffer to replace the one lost.
Implemented in Tes::Buffers::DefaultArrayPool< T >.
abstract void Tes::Buffers::ArrayPool< T >::Return | ( | T[] | array, |
bool | clearArray = false |
||
) | [pure virtual] |
Returns to the pool an array that was previously obtained via Rent on the same ArrayPool{T} instance.
array | The buffer previously obtained from Rent to return to the pool. |
clearArray | If true and if the pool will store the buffer to enable subsequent reuse, Return will clear array of its contents so that a subsequent consumer via Rent 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. |
Once a buffer has been returned to the pool, the caller gives up all ownership of the buffer and must not use it. The reference returned from a given call to Rent must only be returned via Return once. The default ArrayPool{T} may hold onto the returned buffer in order to rent it again, or it may release the returned buffer if it's determined that the pool already has enough buffers stored.
Implemented in Tes::Buffers::DefaultArrayPool< T >.
ArrayPool<T> Tes::Buffers::ArrayPool< T >::Shared [static, get] |
Retrieves a shared ArrayPool{T} instance.
The shared pool provides a default implementation of ArrayPool{T} that's intended for general applicability. It maintains arrays of multiple sizes, and may hand back a larger array than was actually requested, but will never hand back a smaller array than was requested. Renting a buffer from it with Rent will result in an existing buffer being taken from the pool if an appropriate buffer is available or in a new buffer being allocated if one is not available.