Table of Contents

Class ExactLengthArrayPool<T>

Namespace
Enderlook.Pools
Assembly
Enderlook.Pools.dll

Represent a pool of arrays of exact length.

public abstract class ExactLengthArrayPool<T> : ArrayPool<T>

Type Parameters

T

Type of object to pool.

Inheritance
ExactLengthArrayPool<T>
Derived
Inherited Members

Constructors

ExactLengthArrayPool()

protected ExactLengthArrayPool()

Properties

Shared

Retrieves a shared ExactLengthArrayPool<T> instance.
The shared pool has the following features:

  • Instantiates new elements when empty.
  • Resize itself to accommodate all returned elements to the pool.
  • Periodically trims itself removing old elements from the pool (GC-triggered).
  • Is thread-safe.
public static ExactLengthArrayPool<T> Shared { get; }

Property Value

ExactLengthArrayPool<T>

Methods

ApproximateCount()

Gets an approximate count of the objects stored in the pool.
This value is not accurate and may be lower or higher than the actual count.
This is primarily used for debugging purposes.

public abstract int ApproximateCount()

Returns

int

Approximate count of elements in the pool. If this operation is not supported, return -1 instead of throwing.

OfLength(int, bool)

Produces a wrapper ObjectPool<T> that uses the current instance to create arrays of the specified length.

public virtual ArrayObjectPool<T> OfLength(int length, bool clearArrayOnReturn = false)

Parameters

length int

Length of arrays.

clearArrayOnReturn bool

If true and if the pool will store a buffer that is being returned to enable subsequent reuse, will clear the array of its contents so that a subsequent consumer 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.

Returns

ArrayObjectPool<T>

Wrapper of pool.

RentLease(int)

Rent an element from the pool.
If the pool is empty, instantiate a new element.
Implementors of this interface can choose how elements are instantiated and initialized, or throw if instantiation of new elements is not supported.

public Lease<T[]> RentLease(int minimumLength)

Parameters

minimumLength int

The minimum length of the array needed.

Returns

Lease<T[]>

A contained of the rented element. When this container is disposed, the object will be returned to the pool.

RentLease(int, bool)

Rent an element from the pool.
If the pool is empty, instantiate a new element.
Implementors of this interface can choose how elements are instantiated and initialized, or throw if instantiation of new elements is not supported.

public Lease<T[]> RentLease(int minimumLength, bool clearOnReturn)

Parameters

minimumLength int

The minimum length of the array needed.

clearOnReturn bool

If true and if the pool will store the buffer to enable subsequent reuse, will clear the array of its contents so that a subsequent consumer 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.

Returns

Lease<T[]>

A contained of the rented element. When this container is disposed, the object will be returned to the pool.

SharedOfLength(int, bool)

Retrieves a shared ObjectPool<T> instance configured to create arrays of the specified length.
The shared pool has the following features:

  • Instantiates new elements when empty.
  • Resize itself to accommodate all returned elements to the pool.
  • Periodically trims itself removing old elements from the pool (GC-triggered).
  • Is thread-safe.
public static ArrayObjectPool<T> SharedOfLength(int length, bool clearArrayOnReturn = false)

Parameters

length int

Length of arrays.

clearArrayOnReturn bool

If true and if the pool will store a buffer that is being returned to enable subsequent reuse, will clear the array of its contents so that a subsequent consumer 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.

Returns

ArrayObjectPool<T>

Wrapper of pool.

Trim(bool)

Trim the content of the pool.

public abstract void Trim(bool force = false)

Parameters

force bool

If true, the pool is forced to clear all elements inside. Otherwise, the pool may only clear partially or not clear at all if the heuristic says so.