3rd Eye Scene C#
3rd Eye Scene C# documentation
Tes::Buffers::ArrayPool< T > Class Template Reference

Provides a resource pool that enables reusing instances of type T:T[]. More...

Inheritance diagram for Tes::Buffers::ArrayPool< T >:
Tes::Buffers::DefaultArrayPool< T > Tes::Buffers::DefaultArrayPool< T >

List of all members.

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.

Detailed Description

template<T>
class Tes::Buffers::ArrayPool< T >

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.


Member Function Documentation

template<T >
static ArrayPool<T> Tes::Buffers::ArrayPool< T >::Create ( ) [inline, static]

Creates a new ArrayPool{T} instance using default configuration options.

Returns:
A new ArrayPool{T} instance.
template<T >
static ArrayPool<T> Tes::Buffers::ArrayPool< T >::Create ( int  maxArrayLength,
int  maxArraysPerBucket 
) [inline, static]

Creates a new ArrayPool{T} instance using custom configuration options.

Parameters:
maxArrayLengthThe maximum length of array instances that may be stored in the pool.
maxArraysPerBucketThe 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.
Returns:
A new ArrayPool{T} instance with the specified configuration options.

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.

template<T >
abstract T [] Tes::Buffers::ArrayPool< T >::Rent ( int  minimumLength) [pure virtual]

Retrieves a buffer that is at least the requested length.

Parameters:
minimumLengthThe minimum length of the array needed.
Returns:
An T:T[] that is at least minimumLength in length.

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

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

Parameters:
arrayThe buffer previously obtained from Rent to return to the pool.
clearArrayIf 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 >.


Property Documentation

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


The documentation for this class was generated from the following file:
 All Classes Namespaces Functions Variables Enumerations Properties Events