Show / Hide Table of Contents

Class IndexPool

Represents a pool of integer values.

Inheritance
object
IndexPool
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 IndexPool
Remarks

This type can be used to create a custom object pool. In contrast to BoundedObjectPool<T>, the pool of integer values is pre-populated with the values after its construction. So the caller always know whether the particular object is taken from the pool or not.

Constructors

View Source

IndexPool(int)

Initializes a new pool of the desired capacity.

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

The desired number of values in 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

IsEmpty

Gets a value indicating that the pool is empty.

Declaration
public bool IsEmpty { 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(int) method returns false.

View Source

Return(int)

Returns the value previously returned by TryGet(out int) back to the pool.

Declaration
public void Return(int value)
Parameters
Type Name Description
int value

The value to be returned.

Exceptions
Type Condition
OverflowException

TryGet(out int) and Return(int) calls are unbalanced, so the caller is trying to return the value to this pool which is full.

View Source

TryGet(out int)

Tries to get the value from the pool.

Declaration
public bool TryGet(out int value)
Parameters
Type Name Description
int value

The value is in range [0..Capacity).

Returns
Type Description
bool

true if value is taken from the pool successfully; false is this pool is empty.

View Source

TryReturn(int)

Returns the value to this pool.

Declaration
public bool TryReturn(int value)
Parameters
Type Name Description
int value

The value to be returned.

Returns
Type Description
bool

true if the value is returned to the pool; otherwise, false if this pool is frozen.

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
☀
☾