Table of Contents

Class BufferPool

Namespace
Alis.Core.Network
Assembly
Alis.dll

This buffer pool is instance thread safe Use GetBuffer to get a MemoryStream (with a publically accessible buffer) Calling Close on this MemoryStream will clear its internal buffer and return the buffer to the pool for reuse MemoryStreams can grow larger than the DEFAULT_BUFFER_SIZE (or whatever you passed in) and the underlying buffers will be returned to the pool at their larger sizes

public class BufferPool : IBufferPool

Inheritance

Implements

Inherited Members

Constructors

BufferPool()

Initializes a new instance of the Alis.Core.Network.BufferPool class

public BufferPool()

BufferPool(int)

Initializes a new instance of the Alis.Core.Network.BufferPool class

public BufferPool(int bufferSize)

Parameters

bufferSize int

The buffer size

Fields

DefaultBufferSize

The default buffer size

private const int DefaultBufferSize = 16384

Field Value

int

_bufferPoolStack

The buffer pool stack

private readonly ConcurrentStack<byte[]> _bufferPoolStack

Field Value

ConcurrentStack<byte[]>

_bufferSize

The buffer size

private readonly int _bufferSize

Field Value

int

Methods

GetBuffer()

Gets a MemoryStream built from a buffer plucked from a thread safe pool The pool grows automatically. Closing the memory stream clears the buffer and returns it to the pool

public MemoryStream GetBuffer()

Returns

MemoryStream

ReturnBuffer(byte[])

Returns the buffer using the specified buffer

protected internal void ReturnBuffer(byte[] buffer)

Parameters

buffer byte[]

The buffer