Class Pool<T>
- Namespace
- CapyKit
- Assembly
- CapyKit.dll
A managed pool of resources. This class provides a thread-safe way to manage a collection of
objects of type T.
public class Pool<T>
Type Parameters
TThe type of objects to be managed by the pool.
- Inheritance
-
Pool<T>
- Inherited Members
- Extension Methods
Constructors
Pool(IEnumerable<T>)
Initializes a new instance of the Pool<T> class with the specified collection of items.
public Pool(IEnumerable<T> collection)
Parameters
collectionIEnumerable<T>The collection of
Titems with which to seed the pool.
Pool(int)
Initializes a new instance of the Pool<T> class with the specified pool size.
public Pool(int poolSize)
Parameters
poolSizeintThe 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.
public Pool(int poolSize, Func<T> constructorSelector)
Parameters
poolSizeintThe size of the pool.
constructorSelectorFunc<T>The constructor selector used to create new instances of
T.
Methods
GetAvailableItem()
Gets the first available item from the pool and sets its lock.
public PoolItem<T> GetAvailableItem()
Returns
- 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.
public void ReleaseItem(PoolItem<T> item)
Parameters
itemPoolItem<T>The item to release.
Remarks
This method sets the Locked flag to false so that it can be retrieved by GetAvailableItem().