Class Pool<T>
A managed pool of resources. This class provides a thread-safe way to manage a collection of
objects of type T.
Namespace: CapyKit
Assembly: CapyKit.dll
Syntax
public class Pool<T>
Type Parameters
| Name | Description |
|---|---|
| T | The type of objects to be managed by the pool. |
Constructors
Pool(IEnumerable<T>)
Initializes a new instance of the Pool<T> class with the specified collection of items.
Declaration
public Pool(IEnumerable<T> collection)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | collection | The collection of |
Pool(int)
Initializes a new instance of the Pool<T> class with the specified pool size.
Declaration
public Pool(int poolSize)
Parameters
| Type | Name | Description |
|---|---|---|
| int | poolSize | The size of the pool. |
Pool(int, Func<T>)
Initializes a new instance of the Pool<T> class with the specified pool size and constructor selector.
Declaration
public Pool(int poolSize, Func<T> constructorSelector)
Parameters
| Type | Name | Description |
|---|---|---|
| int | poolSize | The size of the pool. |
| Func<T> | constructorSelector | The constructor selector used to create new instances of |
Methods
GetAvailableItem()
Gets the first available item from the pool and sets its lock.
Declaration
public PoolItem<T> GetAvailableItem()
Returns
| Type | Description |
|---|---|
| PoolItem<T> | The first available item from the pool. |
ReleaseItem(PoolItem<T>)
Releases the lock on the specified item and returns it to the pool.
Declaration
public void ReleaseItem(PoolItem<T> item)
Parameters
| Type | Name | Description |
|---|---|---|
| PoolItem<T> | item | The item to release. |
Remarks
This method sets the Locked flag to false so that it can be retrieved by GetAvailableItem().