CapyKit/Docs/api/CapyKit.Pool-1.md

4.1 KiB

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

objectPool<T>

Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Extension Methods

ObjectExtensions.UpdateProperties<Pool<T>>(Pool<T>, Pool<T>), ObjectExtensions.UpdateProperties(object, object)

Constructors

Pool(int)

Initializes a new instance of the 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 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.

Pool(IEnumerable<T>)

Initializes a new instance of the 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.

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 flag to false so that it can be retrieved by .