Class ArrayPool<T>
Represents a set of arrays ready for reuse.
Представляет собой набор массивов готовых к повторному использованию.
Namespace: Platform.Collections.Arrays
Assembly: Platform.Collections.dll
Syntax
public class ArrayPool<T> : object
Type Parameters
Name | Description |
---|---|
T | The array elements type. Тип элементов массива. |
Remarks
Original idea from http://geekswithblogs.net/blackrob/archive/2014/12/18/array-pooling-in-csharp.aspx
Constructors
| Improve this Doc View SourceArrayPool()
Initializes a new instance of the ArrayPool class using the default maximum number of arrays per size.
Инициализирует новый экземпляр класса ArrayPool, используя максимальное количество массивов на каждый размер по умолчанию.
Declaration
public ArrayPool()
ArrayPool(Int32)
Initializes a new instance of the ArrayPool class using the specified maximum number of arrays per size.
Инициализирует новый экземпляр класса ArrayPool, используя указанное максимальное количество массивов на каждый размер.
Declaration
public ArrayPool(int maxArraysPerSize)
Parameters
Type | Name | Description |
---|---|---|
Int32 | maxArraysPerSize | The maximum number of arrays in the pool per size. Максимальное количество массивов в пуле на каждый размер. |
Methods
| Improve this Doc View SourceAllocate(Int64)
Retrieves an array with the specified size from the pool.
Извлекает из пула массив с указанным размером.
Declaration
public virtual T[] Allocate(long size)
Parameters
Type | Name | Description |
---|---|---|
Int64 | size | The allocated array size. Размер выделяемого массива. |
Returns
Type | Description |
---|---|
T[] | An array from the pool or a new array. Массив из пула или новый массив. |
AllocateDisposable(Int64)
Retrieves an array from the pool, which will automatically return to the pool when the container is disposed.
Извлекает из пула массив, который автоматически вернётся в пул при высвобождении контейнера.
Declaration
public Disposable<T[]> AllocateDisposable(long size)
Parameters
Type | Name | Description |
---|---|---|
Int64 | size | The allocated array size. Размер выделяемого массива. |
Returns
Type | Description |
---|---|
Disposable<T[]> | The disposable container containing either a new array or an array from the pool. Высвобождаемый контейнер содержащий либо новый массив, либо массив из пула. |
Clear()
Clears the pool.
Очищает пул.
Declaration
public virtual void Clear()
Free(T[])
Frees the array to the pool for later reuse.
Освобождает массив в пул для последующего повторного использования.
Declaration
public virtual void Free(T[] array)
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array to be freed into the pool. Массив который нужно освободить в пул. |
Resize(Disposable<T[]>, Int64)
Replaces the array with another array from the pool with the specified size.
Заменяет массив на другой массив из пула с указанным размером.
Declaration
public Disposable<T[]> Resize(Disposable<T[]> source, long size)
Parameters
Type | Name | Description |
---|---|---|
Disposable<T[]> | source | The source array. Исходный массив. |
Int64 | size | A new array size. Новый размер массива. |
Returns
Type | Description |
---|---|
Disposable<T[]> | An array with a new size. Массив с новым размером. |