RecyclableMemoryStreamManager class

December 6, 2023 · View on GitHub

Manages pools of RecyclableMemoryStream objects.

public sealed class RecyclableMemoryStreamManager

Public Members

namedescription
RecyclableMemoryStreamManager()Initializes the memory manager with the default block/buffer specifications. This pool may have unbounded growth unless you modify Options.
RecyclableMemoryStreamManager(…)Initializes the memory manager with the given block requiredSize.
LargeBuffersFree { get; }How many buffers are in the large pool.
LargePoolFreeSize { get; }Number of bytes in large pool not currently in use.
LargePoolInUseSize { get; }Number of bytes currently in use by streams from the large pool.
Settings { get; }Settings for controlling the behavior of RecyclableMemoryStream
SmallBlocksFree { get; }How many blocks are in the small pool.
SmallPoolFreeSize { get; }Number of bytes in small pool not currently in use.
SmallPoolInUseSize { get; }Number of bytes currently in use by stream from the small pool.
event BlockCreatedTriggered when a new block is created.
event BufferDiscardedTriggered when a buffer of either type is discarded, along with the reason for the discard.
event LargeBufferCreatedTriggered when a new large buffer is created.
event StreamConvertedToArrayTriggered when a user converts a stream to array.
event StreamCreatedTriggered when a new stream is created.
event StreamDisposedTriggered when a stream is disposed.
event StreamDoubleDisposedTriggered when a stream is disposed of twice (an error).
event StreamFinalizedTriggered when a stream is finalized.
event StreamLengthTriggered when a stream is disposed to report the stream's length.
event StreamOverCapacityTriggered when a stream is requested to expand beyond the maximum length specified by the responsible RecyclableMemoryStreamManager.
event UsageReportPeriodically triggered to report usage statistics.
GetStream()Retrieve a new RecyclableMemoryStream object with no tag and a default initial capacity.
GetStream(…)Retrieve a new RecyclableMemoryStream object with no tag and a default initial capacity. (13 methods)
const DefaultBlockSizeDefault block size, in bytes.
const DefaultLargeBufferMultipleDefault large buffer multiple, in bytes.
const DefaultMaximumBufferSizeDefault maximum buffer size, in bytes.
class BlockCreatedEventArgsArguments for the BlockCreated event.
class BufferDiscardedEventArgsArguments for the BufferDiscarded event.
class EventsETW events for RecyclableMemoryStream.
class LargeBufferCreatedEventArgsArguments for the LargeBufferCreated events.
class OptionsParameters for customizing the behavior of RecyclableMemoryStreamManager
class StreamConvertedToArrayEventArgsArguments for the StreamConvertedToArray event.
class StreamCreatedEventArgsArguments for the StreamCreated event.
class StreamDisposedEventArgsArguments for the StreamDisposed event.
class StreamDoubleDisposedEventArgsArguments for the StreamDoubleDisposed event.
class StreamFinalizedEventArgsArguments for the StreamFinalized event.
class StreamLengthEventArgsArguments for the StreamLength event.
class StreamOverCapacityEventArgsArguments for the StreamOverCapacity event.
class UsageReportEventArgsArguments for the UsageReport event.

Remarks

There are two pools managed in here. The small pool contains same-sized buffers that are handed to streams as they write more data.

For scenarios that need to call GetBuffer, the large pool contains buffers of various sizes, all multiples/exponentials of LargeBufferMultiple (1 MB by default). They are split by size to avoid overly-wasteful buffer usage. There should be far fewer 8 MB buffers than 1 MB buffers, for example.

See Also