Show / Hide Table of Contents

Class BoundedObjectPool<T>

Represents object pool of the fixed size.

Inheritance
object
BoundedObjectPool<T>
Inherited Members
object.GetType()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: DotNext.Collections.Concurrent
Assembly: DotNext.Threading.dll
Syntax
public sealed class BoundedObjectPool<T> where T : class
Type Parameters
Name Description
T

The type of the objects in the pool.

Constructors

View Source

BoundedObjectPool(int)

Initializes a new object pool.

Declaration
public BoundedObjectPool(int desiredCapacity)
Parameters
Type Name Description
int desiredCapacity

The desired number of the objects that can be retained by the pool. The value is rounded to the power of 2 by the pool.

Exceptions
Type Condition
ArgumentOutOfRangeException

desiredCapacity is negative or greater than MaxLength.

Properties

View Source

Capacity

Gets the capacity of the pool.

Declaration
public int Capacity { get; }
Property Value
Type Description
int
View Source

IsFrozen

Gets a value indicating that the pool is frozen and the object cannot be returned back to the pool.

Declaration
public bool IsFrozen { get; }
Property Value
Type Description
bool

Methods

View Source

Freeze()

Freezes the pool in a way when the object cannot be returned back to the pool.

Declaration
public bool Freeze()
Returns
Type Description
bool

true if this method is called for the first time; false if the pool is already frozen.

Remarks

Any subsequent call to the TryReturn(T) method returns false.

View Source

TryGet()

Tries to rent the object.

Declaration
public T? TryGet()
Returns
Type Description
T

The object instance; or null if there are no available objects in the pool.

View Source

TryReturn(T)

Returns the object to this pool.

Declaration
public bool TryReturn(T item)
Parameters
Type Name Description
T item

The object that becomes available for the rent.

Returns
Type Description
bool

true if the object is returned to the pool; otherwise, false if there is no free space in the pool.

Extension Methods

BasicExtensions.As<T>(T)
BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, params ReadOnlySpan<T>)
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾