Skip to main content

Class Pool<T>

Holds a collection of so they can be re-used without allocations

Inheritance
System.Object
Inherited Members
Show
Syntax
public class Pool<T>
where T : class
Type Parameters
NameDescription
T

Constructors

Pool(Pool<T>.CreateNewItemNoCount, Int32, Int32, ILogger)

Creates pool, that does not require Buffer size

Declaration
public Pool(Pool<T>.CreateNewItemNoCount createNew, int startPoolSize, int maxPoolSize, ILogger logger = null)
Parameters
TypeNameDescription
Mirage.SocketLayer.Pool.CreateNewItemNoCount<>createNew
System.Int32startPoolSizehow many buffers to create at start
System.Int32maxPoolSizemax number of buffers in pool
ILoggerlogger

Pool(Pool<T>.CreateNewItem, Int32, Int32, Int32, ILogger)

Creates pool where buffer size will be passed to items when created them

Declaration
public Pool(Pool<T>.CreateNewItem createNew, int bufferSize, int startPoolSize, int maxPoolSize, ILogger logger = null)
Parameters
TypeNameDescription
Mirage.SocketLayer.Pool.CreateNewItem<>createNew
System.Int32bufferSizesize of each buffer
System.Int32startPoolSizehow many buffers to create at start
System.Int32maxPoolSizemax number of buffers in pool
ILoggerlogger

Properties

Metrics

Declaration
public PoolMetrics Metrics { get; }

Methods

Configure(Int32, Int32)

sets max pool size and then creates writers up to new start size

Declaration
public void Configure(int startPoolSize, int maxPoolSize)
Parameters
TypeNameDescription
System.Int32startPoolSize
System.Int32maxPoolSize

Take()

Declaration
public T Take()
Returns
TypeDescription
T

Put(T)

Puts item back in pool, or leaves it for GC if pool is full.

Declaration
public bool Put(T buffer)
Parameters
TypeNameDescription
Tbuffer
Returns
TypeDescription
System.Booleanreturns false if pool is full, in this case, any unmanaged objects should be cleared up