Class ArrayObjectPool<T>
Represent a pool of arrays of a given length.
public abstract class ArrayObjectPool<T> : ObjectPool<T[]>
Type Parameters
TType of element of the array.
- Inheritance
-
ObjectPool<T[]>ArrayObjectPool<T>
- Derived
- Inherited Members
Remarks
The pool has an specified policy of clearing or not arrays on return which is specified at the moment of instantiating the pool, this is used for Return(T).
However, for overriding such policy you can use the method Return(T[], bool).
Constructors
ArrayObjectPool()
protected ArrayObjectPool()
Properties
ShouldClearArrayOnReturnByDefault
Determines the default array clearing strategy.
If this is true, buffers that will be stored to enable subsequent reuse in Return(T[]), will have their content cleared 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.
public abstract bool ShouldClearArrayOnReturnByDefault { get; }
Property Value
Methods
RentLease(bool)
Rent an element from the pool.
If the pool is empty, instantiate a new element.
Implementors of this class can choose how elements are instantiated and initialized, or throw if instantiation of new elements is not supported.
public Lease<T[]> RentLease(bool clearOnReturn)
Parameters
clearOnReturnboolIf 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.
Return(T[])
Return an element to the pool.
If the pool is full, it's an implementation detail whenever the object is free or the pool is resized.
If element is default, it's an implementation detail whenever it throws an exception or ignores the call. However, it should never leave the pool in an invalid state.
public override void Return(T[] element)
Parameters
elementT[]Element to return.
Remarks
It uses a clearing policy specified by ShouldClearArrayOnReturnByDefault.
Return(T[], bool)
Return an element to the pool.
If the pool is full, it's an implementation detail whenever the object is free or the pool is resized.
If element is default, it's an implementation detail whenever it throws an exception or ignores the call. However, it should never leave the pool in an invalid state.
public abstract void Return(T[] element, bool clearArray)
Parameters
elementT[]Element to return.
clearArrayboolIf 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.
Remarks
The overload Return(T) uses a clearing policy specified by ShouldClearArrayOnReturnByDefault.
WithClearArrayOnReturn(bool)
Returns a instance of the pool in which the ShouldClearArrayOnReturnByDefault has been modified.
public virtual ArrayObjectPool<T> WithClearArrayOnReturn(bool clearArrayOnReturnByDefault)
Parameters
clearArrayOnReturnByDefaultboolNew value for ShouldClearArrayOnReturnByDefault.
Returns
- ArrayObjectPool<T>
An instance of the pool in which the ShouldClearArrayOnReturnByDefault has been modified.
It may be a new instance, a pooled one or the same instance if the values matches.