Class BoundedObjectPool<T>
Represents object pool of the fixed size.
Inherited Members
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 SourceBoundedObjectPool(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 |
|
Properties
View SourceCapacity
Gets the capacity of the pool.
Declaration
public int Capacity { get; }
Property Value
| Type | Description |
|---|---|
| int |
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 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(T) method returns false.
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. |
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. |