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 : IBufferPoolInheritance
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
bufferSizeint-
The buffer size
Fields
DefaultBufferSize
The default buffer size
private const int DefaultBufferSize = 16384Field Value
_bufferPoolStack
The buffer pool stack
private readonly ConcurrentStack<byte[]> _bufferPoolStackField Value
_bufferSize
The buffer size
private readonly int _bufferSizeField Value
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
ReturnBuffer(byte[])
Returns the buffer using the specified buffer
protected internal void ReturnBuffer(byte[] buffer)Parameters
bufferbyte[]-
The buffer