Table of Contents

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

T

The 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

collection IEnumerable<T>

The collection of T items 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

poolSize int

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.

public Pool(int poolSize, Func<T> constructorSelector)

Parameters

poolSize int

The size of the pool.

constructorSelector Func<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

item PoolItem<T>

The item to release.

Remarks

This method sets the Locked flag to false so that it can be retrieved by GetAvailableItem().