Class IndexPool
Represents a pool of integer values.
Inherited Members
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 SourceIndexPool(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 |
|
Properties
View SourceCapacity
Gets the capacity of the pool.
Declaration
public int Capacity { get; }
Property Value
| Type | Description |
|---|---|
| int |
IsEmpty
Gets a value indicating that the pool is empty.
Declaration
public bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
View SourceFreeze()
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.
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. |
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. |
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. |