### Install RecyclableMemoryStream via NuGet Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/README.md Use the NuGet Package Manager Console to install the latest version of the library. ```powershell Install-Package Microsoft.IO.RecyclableMemoryStream ``` -------------------------------- ### StreamFinalizedEventArgs Constructor Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.StreamFinalizedEventArgs/StreamFinalizedEventArgs.md Initializes a new instance of the StreamFinalizedEventArgs class with the provided GUID, tag, and allocation stack. ```APIDOC ## StreamFinalizedEventArgs Constructor ### Description Initializes a new instance of the `StreamFinalizedEventArgs` class. ### Method Constructor ### Endpoint N/A (Constructor) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp new StreamFinalizedEventArgs(guid, tag, allocationStack) ``` ### Response #### Success Response (N/A) N/A #### Response Example N/A ## Remarks Arguments for the [`StreamFinalized`](../RecyclableMemoryStreamManager/StreamFinalized.md) event. ## See Also * class [StreamFinalizedEventArgs](../RecyclableMemoryStreamManager.StreamFinalizedEventArgs.md) * namespace [Microsoft.IO](../../Microsoft.IO.RecyclableMemoryStream.md) ``` -------------------------------- ### StreamConvertedToArrayEventArgs Constructor Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.StreamConvertedToArrayEventArgs/StreamConvertedToArrayEventArgs.md Initializes a new instance of the StreamConvertedToArrayEventArgs class with the provided GUID, tag, stack, and length. ```APIDOC ## StreamConvertedToArrayEventArgs Constructor ### Description Initializes a new instance of the `StreamConvertedToArrayEventArgs` class. ### Method Constructor ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **guid** (Guid) - Required - Unique ID of the stream. - **tag** (string?) - Optional - Tag of the stream. - **stack** (string?) - Optional - Stack of ToArray call. - **length** (long) - Required - Length of stream. ### Request Example ```csharp new StreamConvertedToArrayEventArgs(new Guid("00000000-0000-0000-0000-000000000000"), "myTag", "myStack", 1024); ``` ### Response #### Success Response (200) None (This is a constructor) #### Response Example None ``` -------------------------------- ### RecyclableMemoryStreamManager.GetStream(Guid id, string? tag) Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager/GetStream.md Retrieves a new RecyclableMemoryStream object with the given tag and a default initial capacity, identified by a GUID. ```APIDOC ## RecyclableMemoryStreamManager.GetStream(Guid id, string? tag) ### Description Retrieve a new `RecyclableMemoryStream` object with the given tag and a default initial capacity. ### Method GET ### Endpoint /api/streams/{id} ### Parameters #### Path Parameters - **id** (Guid) - Required - A unique identifier which can be used to trace usages of the stream. #### Query Parameters - **tag** (string) - Optional - A tag which can be used to track the source of the stream. ### Response #### Success Response (200) - **stream** (RecyclableMemoryStream) - A new `RecyclableMemoryStream` object. #### Response Example { "stream": "" } ``` -------------------------------- ### RecyclableMemoryStreamManager.GetStream(Guid id) Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager/GetStream.md Retrieves a new RecyclableMemoryStream object with no tag and a default initial capacity, identified by a GUID. ```APIDOC ## RecyclableMemoryStreamManager.GetStream(Guid id) ### Description Retrieve a new `RecyclableMemoryStream` object with no tag and a default initial capacity. ### Method GET ### Endpoint /api/streams/{id} ### Parameters #### Path Parameters - **id** (Guid) - Required - A unique identifier which can be used to trace usages of the stream. ### Response #### Success Response (200) - **stream** (RecyclableMemoryStream) - A new `RecyclableMemoryStream` object. #### Response Example { "stream": "" } ``` -------------------------------- ### Set BlockSize Property Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.Options/BlockSize.md Gets or sets the size of the pooled blocks. This must be greater than 0. The default size is 131,072 (128KB). ```csharp public int BlockSize { get; set; } ``` -------------------------------- ### Get or Set RecyclableMemoryStream Capacity Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStream/Capacity.md Use this property to get or set the capacity of the stream. Note that explicitly setting a lower capacity than the current value has no effect. Capacity increases automatically when writing past the current capacity, up to MaximumStreamCapacity. ```csharp public override int Capacity { get; set; } ``` -------------------------------- ### Read into byte[] with offset and count Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStream/Read.md Use this overload to read a specified number of bytes into a byte array starting at a given offset. Validate that the buffer is not null and that offset and count are within valid ranges to prevent exceptions. ```csharp public override int Read(byte[] buffer, int offset, int count) ``` -------------------------------- ### RecyclableMemoryStreamManager.Options.BlockSize Property Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.Options/BlockSize.md Gets or sets the size of the pooled blocks. This must be greater than 0. ```APIDOC ## RecyclableMemoryStreamManager.Options.BlockSize Property ### Description Gets or sets the size of the pooled blocks. This must be greater than 0. ### Remarks The default size 131,072 (128KB) ### See Also * class [Options](../RecyclableMemoryStreamManager.Options.md) * namespace [Microsoft.IO](../../Microsoft.IO.RecyclableMemoryStream.md) ``` -------------------------------- ### WriteTo(byte[] buffer, long offset, long count, int targetOffset) Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStream/WriteTo.md Writes a specified number of bytes from the current stream, starting at a given offset, to a destination byte array at a specified target offset. ```APIDOC ## WriteTo(byte[] buffer, long offset, long count, int targetOffset) ### Description Writes bytes from the current stream to a destination `byte` array. ### Method void ### Endpoint N/A (Method within a class) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None (void method) #### Response Example None ### Exceptions - **ArgumentNullException**: `buffer` is null. - **ArgumentOutOfRangeException**: `offset` is less than 0, or `offset` + `count` is beyond this stream's length. - **ArgumentOutOfRangeException**: `targetOffset` is less than 0, or `targetOffset` + `count` is beyond the target `buffer`'s length. - **ObjectDisposedException**: Object has been disposed. ``` -------------------------------- ### Get Underlying Buffer with TryGetBuffer Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStream/TryGetBuffer.md Use TryGetBuffer to obtain an ArraySegment of the stream's contents. Returns true if a buffer is available, false otherwise. The returned ArraySegment provides a reference to the underlying bytes. ```csharp public override bool TryGetBuffer(out ArraySegment buffer) ``` -------------------------------- ### WriteTo(byte[] buffer, long offset, long count) Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStream/WriteTo.md Writes a specified number of bytes from the current stream, starting at a given offset, to a destination byte array. ```APIDOC ## WriteTo(byte[] buffer, long offset, long count) ### Description Writes bytes from the current stream to a destination `byte` array. ### Method void ### Endpoint N/A (Method within a class) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None (void method) #### Response Example None ### Exceptions - **ArgumentNullException**: `buffer` is null. - **ArgumentOutOfRangeException**: `offset` is less than 0, or `offset` + `count` is beyond this stream's length. - **ObjectDisposedException**: Object has been disposed. ``` -------------------------------- ### WriteTo(Stream stream, long offset, long count) Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStream/WriteTo.md Synchronously writes a specified number of bytes from the current stream, starting at a given offset, to another stream. ```APIDOC ## WriteTo(Stream stream, long offset, long count) ### Description Synchronously writes this stream's bytes, starting at offset, for count bytes, to the argument stream. ### Method void ### Endpoint N/A (Method within a class) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None (void method) #### Response Example None ### Exceptions - **ArgumentNullException**: `stream` is null. - **ArgumentOutOfRangeException**: `offset` is less than 0, or `offset` + `count` is beyond this stream's length. - **ObjectDisposedException**: Object has been disposed. ``` -------------------------------- ### Get ReadOnlySequence from RecyclableMemoryStream Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStream/GetReadOnlySequence.md Call this method to obtain a ReadOnlySequence of the stream's contents. Be aware that calling Write(), GetMemory(), GetSpan(), Dispose(), or Close() after this method invalidates the sequence. ```csharp public ReadOnlySequence GetReadOnlySequence() ``` -------------------------------- ### RecyclableMemoryStreamManager.GetStream(Guid id, string tag, ReadOnlySpan buffer) Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager/GetStream.md Retrieves a new RecyclableMemoryStream with a given ID and tag, copying content from a provided buffer. The original buffer is not used after construction. ```APIDOC ## RecyclableMemoryStreamManager.GetStream(Guid id, string tag, ReadOnlySpan buffer) ### Description Retrieve a new `RecyclableMemoryStream` object with the given tag and with contents copied from the provided buffer. The provided buffer is not wrapped or used after construction. ### Method GET ### Endpoint /api/streams ### Parameters #### Query Parameters - **id** (Guid) - Required - A unique identifier which can be used to trace usages of the stream. - **tag** (string) - Optional - A tag which can be used to track the source of the stream. - **buffer** (ReadOnlySpan) - Required - The byte buffer to copy data from. ### Response #### Success Response (200) - **stream** (RecyclableMemoryStream) - A `RecyclableMemoryStream` object. ### Remarks The new stream's position is set to the beginning of the stream when returned. ``` -------------------------------- ### Get the unique ID of a stream Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.StreamConvertedToArrayEventArgs/Id.md This property provides a unique Guid for the stream. It is read-only and assigned when the event arguments are created. ```csharp public Guid Id { get; } ``` -------------------------------- ### Create Default Options Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.Options/Options.md Creates a new Options object with default settings. Use this when no specific configuration is required. ```csharp public Options() ``` -------------------------------- ### Create Options with Specific Settings Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.Options/Options.md Creates a new Options object with custom settings for buffer sizes and pool management. Configure these parameters to fine-tune memory stream performance. ```csharp public Options(int blockSize, int largeBufferMultiple, int maximumBufferSize, long maximumSmallPoolFreeBytes, long maximumLargePoolFreeBytes) ``` -------------------------------- ### Initialize RecyclableMemoryStreamManager with Default Options Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager/RecyclableMemoryStreamManager.md Use this constructor to initialize the memory manager with default block and buffer specifications. The pool may grow unboundedly unless options are modified. ```csharp public RecyclableMemoryStreamManager() ``` -------------------------------- ### RecyclableMemoryStreamManager.Options Constructor (Default) Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.Options/Options.md Creates a new Options object with default settings. ```APIDOC ## Options() ### Description Creates a new `Options` object with default settings. ### Method `public Options()` ### Endpoint N/A (Constructor) ### Parameters None ### Request Example ```csharp var options = new RecyclableMemoryStreamManager.Options(); ``` ### Response N/A (Constructor) ``` -------------------------------- ### Providing an Existing Buffer Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/README.md Initialize a stream with an existing buffer. Note that the data from the provided buffer is copied into a pool-owned buffer. ```csharp var stream = manager.GetStream("Program.Main", sourceBuffer, 0, sourceBuffer.Length); ``` -------------------------------- ### StreamOverCapacityEventArgs.MaximumCapacity Property Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.StreamOverCapacityEventArgs/MaximumCapacity.md Gets the maximum capacity of the stream. ```APIDOC ## StreamOverCapacityEventArgs.MaximumCapacity Property ### Description Gets the maximum capacity of the stream. ### Property Type `long` ### Access Public read-only property. ``` -------------------------------- ### RecyclableMemoryStream.Length Property Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStream/Length.md Gets the number of bytes written to this stream. ```APIDOC ## RecyclableMemoryStream.Length Property ### Description Gets the number of bytes written to this stream. ### Method GET ### Endpoint N/A (Property) ### Parameters N/A ### Request Example N/A ### Response #### Success Response (200) - **Length** (long) - The number of bytes written to the stream. #### Response Example N/A (Property access) ### Exceptions - **ObjectDisposedException**: Thrown if the object has been disposed. ### Remarks If the buffer has already been converted to a large buffer, then the maximum length is limited by the maximum allowed array length in .NET. ``` -------------------------------- ### Writing BigInteger using IBufferWriter Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/README.md Demonstrates using IBufferWriter methods GetSpan, Advance to write data efficiently without intermediate allocations. This avoids GC pressure. ```csharp var bigInt = BigInteger.Parse("123456789013374299100987654321"); using (var stream = manager.GetStream()) { Span buffer = stream.GetSpan(bigInt.GetByteCount()); bigInt.TryWriteBytes(buffer, out int bytesWritten); stream.Advance(bytesWritten); } ``` -------------------------------- ### Get Length of StreamConvertedToArrayEventArgs Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.StreamConvertedToArrayEventArgs/Length.md Retrieves the length of the stack. This property is read-only. ```csharp public long Length { get; } ``` -------------------------------- ### Initialize RecyclableMemoryStreamManager with Custom Options Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager/RecyclableMemoryStreamManager.md Initializes the memory manager with custom options for stream behavior. Ensure that the provided options meet the specified constraints to avoid InvalidOperationException. ```csharp public RecyclableMemoryStreamManager(Options options) ``` -------------------------------- ### RecyclableMemoryStream Constructor (5 of 6) Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStream/RecyclableMemoryStream.md Initializes a new instance of the RecyclableMemoryStream class with a memory manager, a tag, and a requested size. ```APIDOC ## RecyclableMemoryStream Constructor ### Description Initializes a new instance of the `RecyclableMemoryStream` class. ### Method Constructor ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ### Parameters - **memoryManager** (RecyclableMemoryStreamManager) - Required - The memory manager. - **tag** (string?) - Optional - A string identifying this stream for logging and debugging purposes. - **requestedSize** (long) - Required - The initial requested size to prevent future allocations. ``` -------------------------------- ### StreamOverCapacityEventArgs.RequestedCapacity Property Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.StreamOverCapacityEventArgs/RequestedCapacity.md Gets the requested capacity for a stream that has exceeded its capacity limit. ```APIDOC ## StreamOverCapacityEventArgs.RequestedCapacity Property ### Description Gets the requested capacity for a stream that has exceeded its capacity limit. ### Method get ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response #### Success Response (200) - **RequestedCapacity** (long) - The requested capacity. #### Response Example ```json { "RequestedCapacity": 1024 } ``` ``` -------------------------------- ### RecyclableMemoryStream Constructor (6 of 6) Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStream/RecyclableMemoryStream.md Initializes a new instance of the RecyclableMemoryStream class with a memory manager, an ID, a tag, and a requested size. ```APIDOC ## RecyclableMemoryStream Constructor ### Description Initializes a new instance of the `RecyclableMemoryStream` class. ### Method Constructor ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ### Parameters - **memoryManager** (RecyclableMemoryStreamManager) - Required - The memory manager. - **id** (Guid) - Required - A unique identifier which can be used to trace usages of the stream. - **tag** (string?) - Optional - A string identifying this stream for logging and debugging purposes. - **requestedSize** (long) - Required - The initial requested size to prevent future allocations. ``` -------------------------------- ### RecyclableMemoryStreamManager.BlockCreatedEventArgs.SmallPoolInUse Property Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.BlockCreatedEventArgs/SmallPoolInUse.md Gets the number of bytes currently in use from the small pool. ```APIDOC ## RecyclableMemoryStreamManager.BlockCreatedEventArgs.SmallPoolInUse Property ### Description How many bytes are currently in use from the small pool. ### Property Type `long` ### Access Level `public` ### Example ```csharp long bytesInUse = eventArgs.SmallPoolInUse; ``` ### See Also * [BlockCreatedEventArgs](../RecyclableMemoryStreamManager.BlockCreatedEventArgs.md) * [Microsoft.IO Namespace](../../Microsoft.IO.RecyclableMemoryStream.md) ``` -------------------------------- ### RecyclableMemoryStreamManager.Options Constructor (Parameterized) Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.Options/Options.md Creates a new Options object with specified configuration values. ```APIDOC ## Options(int blockSize, int largeBufferMultiple, int maximumBufferSize, long maximumSmallPoolFreeBytes, long maximumLargePoolFreeBytes) ### Description Creates a new `Options` object with the most common options pre-configured. ### Method `public Options(int blockSize, int largeBufferMultiple, int maximumBufferSize, long maximumSmallPoolFreeBytes, long maximumLargePoolFreeBytes)` ### Endpoint N/A (Constructor) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **blockSize** (int) - Description: Size of the blocks in the small pool. - **largeBufferMultiple** (int) - Description: Size of the large buffer multiple. - **maximumBufferSize** (int) - Description: Maximum poolable buffer size. - **maximumSmallPoolFreeBytes** (long) - Description: Maximum bytes to hold in the small pool. - **maximumLargePoolFreeBytes** (long) - Description: Maximum bytes to hold in each of the large pools. ### Request Example ```csharp var options = new RecyclableMemoryStreamManager.Options(blockSize: 1024, largeBufferMultiple: 16, maximumBufferSize: 1048576, maximumSmallPoolFreeBytes: 100000000, maximumLargePoolFreeBytes: 1000000000); ``` ### Response N/A (Constructor) ``` -------------------------------- ### StreamFinalizedEventArgs.Id Property Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.StreamFinalizedEventArgs/Id.md The Id property returns a unique GUID that identifies the stream instance. ```APIDOC ## StreamFinalizedEventArgs.Id Property ### Description Unique ID for the stream. ### Property Type Guid ### Access Public get accessor. ``` -------------------------------- ### RecyclableMemoryStream Constructor (3 of 6) Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStream/RecyclableMemoryStream.md Initializes a new instance of the RecyclableMemoryStream class with a memory manager and a tag for logging. ```APIDOC ## RecyclableMemoryStream Constructor ### Description Initializes a new instance of the `RecyclableMemoryStream` class. ### Method Constructor ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ### Parameters - **memoryManager** (RecyclableMemoryStreamManager) - Required - The memory manager. - **tag** (string?) - Optional - A string identifying this stream for logging and debugging purposes. ``` -------------------------------- ### StreamCreatedEventArgs.Id Property Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.StreamCreatedEventArgs/Id.md The Id property provides a unique Guid for each stream created by the RecyclableMemoryStreamManager. ```APIDOC ## StreamCreatedEventArgs.Id Property ### Description Unique ID for the stream. ### Method GET ### Endpoint N/A (Property) ### Parameters N/A ### Request Example N/A ### Response #### Success Response (200) - **Id** (Guid) - The unique identifier for the stream. #### Response Example ```json { "Id": "a1b2c3d4-e5f6-7890-1234-567890abcdef" } ``` ``` -------------------------------- ### RecyclableMemoryStream Constructor (1 of 6) Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStream/RecyclableMemoryStream.md Initializes a new instance of the RecyclableMemoryStream class with a memory manager. ```APIDOC ## RecyclableMemoryStream Constructor ### Description Initializes a new instance of the `RecyclableMemoryStream` class. ### Method Constructor ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ### Parameters - **memoryManager** (RecyclableMemoryStreamManager) - Required - The memory manager. ``` -------------------------------- ### Get Requested Stream Size Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.StreamCreatedEventArgs/RequestedSize.md Retrieves the size that was requested for the stream. This property is read-only. ```csharp public long RequestedSize { get; } ``` -------------------------------- ### RecyclableMemoryStream Constructor (4 of 6) Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStream/RecyclableMemoryStream.md Initializes a new instance of the RecyclableMemoryStream class with a memory manager, an ID, and a tag. ```APIDOC ## RecyclableMemoryStream Constructor ### Description Initializes a new instance of the `RecyclableMemoryStream` class. ### Method Constructor ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ### Parameters - **memoryManager** (RecyclableMemoryStreamManager) - Required - The memory manager. - **id** (Guid) - Required - A unique identifier which can be used to trace usages of the stream. - **tag** (string?) - Optional - A string identifying this stream for logging and debugging purposes. ``` -------------------------------- ### UsageReportEventArgs Constructor Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.UsageReportEventArgs/UsageReportEventArgs.md Initializes a new instance of the UsageReportEventArgs class. Use this to create an event argument object containing memory usage details for the small and large pools. ```csharp public UsageReportEventArgs(long smallPoolInUseBytes, long smallPoolFreeBytes, long largePoolInUseBytes, long largePoolFreeBytes) ``` -------------------------------- ### RecyclableMemoryStreamManager.LargeBufferCreatedEventArgs.Id Property Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.LargeBufferCreatedEventArgs/Id.md The Id property returns a unique GUID that identifies the stream associated with the LargeBufferCreatedEventArgs. ```APIDOC ## RecyclableMemoryStreamManager.LargeBufferCreatedEventArgs.Id Property ### Description Unique ID for the stream. ### Property Signature ```csharp public Guid Id { get; } ``` ### See Also * class [LargeBufferCreatedEventArgs](../RecyclableMemoryStreamManager.LargeBufferCreatedEventArgs.md) * namespace [Microsoft.IO](../../Microsoft.IO.RecyclableMemoryStream.md) ``` -------------------------------- ### BufferDiscardedEventArgs.Id Property Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.BufferDiscardedEventArgs/Id.md The Id property returns a unique GUID that identifies the stream associated with the BufferDiscardedEventArgs. ```APIDOC ## BufferDiscardedEventArgs.Id Property ### Description Unique ID for the stream. ### Property Type System.Guid ### Access Public Read-only ### Example ```csharp public Guid Id { get; } ``` ``` -------------------------------- ### Configuring RecyclableMemoryStreamManager Options Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/README.md Customize pool behavior by setting options such as BlockSize, LargeBufferMultiple, and MaximumBufferSize. Unbounded memory growth can occur if MaximumFreeLargePoolBytes and MaximumFreeSmallPoolBytes are not set. ```csharp var options = new RecyclableMemoryStreamManager.Options() { BlockSize = 1024, LargeBufferMultiple = 1024 * 1024, MaximumBufferSize = 16 * 1024 * 1024, GenerateCallStacks = true, AggressiveBufferReturn = true, MaximumLargePoolFreeBytes = 16 * 1024 * 1024 * 4, MaximumSmallPoolFreeBytes = 100 * 1024, }; var manager = new RecyclableMemoryStreamManager(options); ``` -------------------------------- ### UsageReportEventArgs Constructor Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.UsageReportEventArgs/UsageReportEventArgs.md Arguments for the UsageReport event. ```APIDOC ## UsageReportEventArgs Constructor ### Description Initializes a new instance of the UsageReportEventArgs class. ### Method Constructor ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ### Remarks Arguments for the `UsageReport` event. ### Parameters - **smallPoolInUseBytes** (long) - Description: Bytes from the small pool currently in use. - **smallPoolFreeBytes** (long) - Description: Bytes from the small pool currently available. - **largePoolInUseBytes** (long) - Description: Bytes from the large pool currently in use. - **largePoolFreeBytes** (long) - Description: Bytes from the large pool currently available. ### See Also * class `UsageReportEventArgs` * namespace `Microsoft.IO` ``` -------------------------------- ### RecyclableMemoryStreamManager Constructors Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.md Details the constructors available for initializing the RecyclableMemoryStreamManager. ```APIDOC ## RecyclableMemoryStreamManager Constructors ### Description Initializes the memory manager with default or specified block/buffer configurations. ### Method - **RecyclableMemoryStreamManager()** Initializes the memory manager with the default block/buffer specifications. This pool may have unbounded growth unless you modify [`Options`](./RecyclableMemoryStreamManager.Options.md). - **RecyclableMemoryStreamManager(long requiredSize)** Initializes the memory manager with the given block requiredSize. ``` -------------------------------- ### RecyclableMemoryStream Constructor (2 of 6) Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStream/RecyclableMemoryStream.md Initializes a new instance of the RecyclableMemoryStream class with a memory manager and a unique ID. ```APIDOC ## RecyclableMemoryStream Constructor ### Description Initializes a new instance of the `RecyclableMemoryStream` class. ### Method Constructor ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ### Parameters - **memoryManager** (RecyclableMemoryStreamManager) - Required - The memory manager. - **id** (Guid) - Required - A unique identifier which can be used to trace usages of the stream. ``` -------------------------------- ### Get Actual Stream Size Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.StreamCreatedEventArgs/ActualSize.md This property returns the actual size of the stream that was created. It is part of the StreamCreatedEventArgs class. ```csharp public long ActualSize { get; } ``` -------------------------------- ### Initialize RecyclableMemoryStreamManager.Events Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.Events/Events.md This is the default constructor for the Events class. It is used to create a new instance of the Events class. ```csharp public Events() ``` -------------------------------- ### RecyclableMemoryStreamManager.Options.UseExponentialLargeBuffer Property Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.Options/UseExponentialLargeBuffer.md Gets or sets a value indicating whether to use the exponential allocation strategy for large buffers. The default value is false. ```APIDOC ## RecyclableMemoryStreamManager.Options.UseExponentialLargeBuffer Property ### Description Gets or sets a value indicating whether to use the exponential allocation strategy for large buffers. This strategy is described in the main documentation. ### Property Type `bool` ### Default Value `false` ### Remarks The default value for this property is `false`. ### See Also * class [Options](../RecyclableMemoryStreamManager.Options.md) * namespace [Microsoft.IO](../../Microsoft.IO.RecyclableMemoryStream.md) ``` -------------------------------- ### RecyclableMemoryStream Methods Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStream.md Details the various methods available for interacting with the RecyclableMemoryStream, including buffer management, reading, writing, seeking, and copying stream content. ```APIDOC ## RecyclableMemoryStream Methods ### Description Methods for operating on the `RecyclableMemoryStream`. ### Method Various (GET, POST, PUT, DELETE, etc. depending on the operation) ### Endpoint N/A ### Parameters (Parameters vary by method. See individual method descriptions below.) ### Request Example N/A ### Response (Responses vary by method. See individual method descriptions below.) #### Advance - **Description**: Notifies the stream that *count* bytes were written to the buffer returned by [`GetMemory`](./RecyclableMemoryStream/GetMemory.md) or [`GetSpan`](./RecyclableMemoryStream/GetSpan.md). Seeks forward by *count* bytes. - **Method**: N/A (Method signature implies usage within the class) #### Close - **Description**: Equivalent to `Dispose`. - **Method**: N/A (Method signature implies usage within the class) #### CopyTo - **Description**: Copies stream content. - **Method**: N/A (Method signature implies usage within the class) #### CopyToAsync - **Description**: Asynchronously reads all the bytes from the current position in this stream and writes them to another stream. - **Method**: N/A (Method signature implies usage within the class) #### GetBuffer - **Description**: Returns a single buffer containing the contents of the stream. The buffer may be longer than the stream length. - **Method**: N/A (Method signature implies usage within the class) #### GetMemory - **Description**: Returns a writable buffer that can be used to write data to the stream. - **Method**: N/A (Method signature implies usage within the class) #### GetReadOnlySequence - **Description**: Returns a sequence containing the contents of the stream. - **Method**: N/A (Method signature implies usage within the class) #### GetSpan - **Description**: Returns a span that can be used to write data to the stream. - **Method**: N/A (Method signature implies usage within the class) #### Read - **Description**: Reads from the current position into the provided buffer. - **Method**: N/A (Method signature implies usage within the class) #### ReadByte - **Description**: Reads a single byte from the current position in the stream. - **Method**: N/A (Method signature implies usage within the class) #### SafeRead - **Description**: Reads from the specified position into the provided buffer. - **Method**: N/A (Method signature implies usage within the class) #### SafeReadByte - **Description**: Reads a single byte from the specified position in the stream. - **Method**: N/A (Method signature implies usage within the class) #### Seek - **Description**: Sets the position to the offset from the seek location. - **Method**: N/A (Method signature implies usage within the class) #### SetLength - **Description**: Sets the length of the stream. - **Method**: N/A (Method signature implies usage within the class) #### ToArray - **Description**: Returns a new array with a copy of the buffer's contents. This method should be used with caution as it can negate the benefits of pooled buffers. - **Method**: N/A (Method signature implies usage within the class) #### ToString - **Description**: Returns a useful string for debugging. This should not normally be called in actual production code. - **Method**: N/A (Method signature implies usage within the class) #### TryGetBuffer - **Description**: Returns an `ArraySegment` that wraps a single buffer containing the contents of the stream. - **Method**: N/A (Method signature implies usage within the class) #### Write - **Description**: Writes the buffer to the stream. - **Method**: N/A (Method signature implies usage within the class) #### WriteByte - **Description**: Writes a single byte to the current position in the stream. - **Method**: N/A (Method signature implies usage within the class) #### WriteTo - **Description**: Synchronously writes this stream's bytes to the argument stream or a specified portion of it. - **Method**: N/A (Method signature implies usage within the class) ``` -------------------------------- ### RecyclableMemoryStreamManager(Options options) Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager/RecyclableMemoryStreamManager.md Initializes the memory manager with the given block requiredSize. ```APIDOC ## RecyclableMemoryStreamManager(Options options) ### Description Initializes the memory manager with the given block requiredSize. ### Method Constructor ### Endpoint N/A ### Parameters #### Request Body - **options** (Options) - Required - Object specifying options for stream behavior. ### Request Example ```json { "options": { "BlockSize": { "BlockSize": 1024 }, "LargeBufferMultiple": { "LargeBufferMultiple": 16 }, "MaximumBufferSize": { "MaximumBufferSize": 1048576 }, "MaximumSmallPoolFreeBytes": { "MaximumSmallPoolFreeBytes": 10485760 }, "MaximumLargePoolFreeBytes": { "MaximumLargePoolFreeBytes": 104857600 } } } ``` ### Response #### Success Response (200) None (Constructor) #### Response Example None ``` -------------------------------- ### RecyclableMemoryStream.Position Property Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStream/Position.md Gets or sets the current position within the stream. The position is the number of bytes from the stream's beginning to the current position. ```APIDOC ## RecyclableMemoryStream.Position Property ### Description Gets or sets the current position within the stream. The position is the number of bytes from the stream's beginning to the current position. ### Method `get`, `set` ### Endpoint N/A (Property of a class) ### Parameters #### Set Parameters - **Position** (long) - Required - The new position to set within the stream. ### Request Example ```csharp long currentPosition = memoryStream.Position; memoryStream.Position = 1024; ``` ### Response #### Success Response (Get) - **Position** (long) - The current position in the stream. #### Response Example (Get) ```csharp // Assuming memoryStream is an instance of RecyclableMemoryStream long currentPosition = memoryStream.Position; Console.WriteLine($"Current position: {currentPosition}"); ``` ### Exceptions - **ObjectDisposedException**: The object has been disposed. - **ArgumentOutOfRangeException**: A negative value was passed for the position. - **InvalidOperationException**: The stream is in large-buffer mode, but an attempt was made to set the position past the maximum allowed array length. ``` -------------------------------- ### RecyclableMemoryStreamManager() Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager/RecyclableMemoryStreamManager.md Initializes the memory manager with the default block/buffer specifications. This pool may have unbounded growth unless you modify Options. ```APIDOC ## RecyclableMemoryStreamManager() ### Description Initializes the memory manager with the default block/buffer specifications. This pool may have unbounded growth unless you modify Options. ### Method Constructor ### Endpoint N/A ### Parameters None ### Request Example None ### Response None ``` -------------------------------- ### RecyclableMemoryStream.Capacity64 Property Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStream/Capacity64.md Use this property to get or set the 64-bit capacity of the stream. This is particularly useful for streams that may exceed `int.MaxValue` in length. ```csharp public long Capacity64 { get; set; } ``` -------------------------------- ### RecyclableMemoryStream.SafeRead (byte[], int, int) Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStream/SafeRead.md Reads a specified number of bytes from the stream into a byte array, starting at a given offset and stream position. ```APIDOC ## SafeRead (byte[], int, int) ### Description Reads from the specified position into the provided buffer. ### Method Not applicable (C# method signature) ### Endpoint Not applicable (C# method signature) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **int** - The number of bytes read. #### Response Example None ### Exceptions - **ArgumentNullException** - *buffer* is null. - **ArgumentOutOfRangeException** - *offset* or *count* is less than 0. - **ArgumentException** - *offset* subtracted from the buffer length is less than *count*. - **ObjectDisposedException** - Object has been disposed. ``` -------------------------------- ### GetStream with Default Capacity Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager/GetStream.md Retrieves a new RecyclableMemoryStream with no tag and a default initial capacity. Use this for general-purpose stream creation when specific capacity or tagging is not required. ```csharp public RecyclableMemoryStream GetStream() ``` -------------------------------- ### RecyclableMemoryStreamManager.GetStream(Guid id, string tag, long requiredSize) Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager/GetStream.md Retrieves a new RecyclableMemoryStream with a given ID and tag, ensuring a minimum specified capacity. ```APIDOC ## RecyclableMemoryStreamManager.GetStream(Guid id, string tag, long requiredSize) ### Description Retrieve a new `RecyclableMemoryStream` object with the given tag and at least the given capacity. ### Method GET ### Endpoint /api/streams ### Parameters #### Query Parameters - **id** (Guid) - Required - A unique identifier which can be used to trace usages of the stream. - **tag** (string) - Optional - A tag which can be used to track the source of the stream. - **requiredSize** (long) - Required - The minimum desired capacity for the stream. ### Response #### Success Response (200) - **stream** (RecyclableMemoryStream) - A `RecyclableMemoryStream` object. ### Remarks The new stream's position is set to the beginning of the stream when returned. ``` -------------------------------- ### RecyclableMemoryStreamManager.GetStream(Guid, string, byte[], int, int) Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager/GetStream.md Retrieves a new RecyclableMemoryStream object with a specified ID and tag, copying content from a provided byte buffer. ```APIDOC ## RecyclableMemoryStreamManager.GetStream(Guid id, string? tag, byte[] buffer, int offset, int count) ### Description Retrieve a new [`RecyclableMemoryStream`](../RecyclableMemoryStream.md) object with the given tag and with contents copied from the provided buffer. The provided buffer is not wrapped or used after construction. ### Method GET ### Endpoint /api/streams/from-buffer-with-id ### Parameters #### Path Parameters - **id** (Guid) - Required - A unique identifier which can be used to trace usages of the stream. - **tag** (string) - Optional - A tag which can be used to track the source of the stream. - **buffer** (byte[]) - Required - The byte buffer to copy data from. - **offset** (int) - Required - The offset from the start of the buffer to copy from. - **count** (int) - Required - The number of bytes to copy from the buffer. ### Request Example ```json { "id": "b2c3d4e5-f6a7-8901-2345-67890abcdef1", "tag": "buffer-id-source", "buffer": "AQIDBAUGBwgJ...", "offset": 0, "count": 10 } ``` ### Response #### Success Response (200) - **RecyclableMemoryStream** (object) - A new RecyclableMemoryStream instance. #### Response Example ```json { "stream": "" } ``` ``` -------------------------------- ### Basic MemoryStream Replacement Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/README.md Replace standard MemoryStream with RecyclableMemoryStream for improved performance. Ensure RecyclableMemoryStreamManager is a singleton for the application's lifetime. ```csharp class Program { private static readonly RecyclableMemoryStreamManager manager = new RecyclableMemoryStreamManager(); static void Main(string[] args) { var sourceBuffer = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }; using (var stream = manager.GetStream()) { stream.Write(sourceBuffer, 0, sourceBuffer.Length); } } } ``` -------------------------------- ### RecyclableMemoryStreamManager.Options.MaximumStreamCapacity Property Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.Options/MaximumStreamCapacity.md Gets or sets the maximum stream capacity in bytes. A value of 0 indicates no limit. Attempts to set a larger capacity will result in an exception. ```APIDOC ## RecyclableMemoryStreamManager.Options.MaximumStreamCapacity Property ### Description Gets or sets the maximum stream capacity in bytes. Attempts to set a larger capacity will result in an exception. ### Remarks The default value of 0 indicates no limit. ### See Also * class [Options](../RecyclableMemoryStreamManager.Options.md) * namespace [Microsoft.IO](../../Microsoft.IO.RecyclableMemoryStream.md) ``` -------------------------------- ### Get Small Pool Usage in BlockCreatedEventArgs Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.BlockCreatedEventArgs/SmallPoolInUse.md Access the SmallPoolInUse property to retrieve the number of bytes currently allocated from the small pool. This is useful for monitoring memory usage. ```csharp public long SmallPoolInUse { get; } ``` -------------------------------- ### Close Method Signature Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStream/Close.md This is the signature for the Close method. It is equivalent to Dispose. ```csharp public override void Close() ``` -------------------------------- ### GetStream with Tag, Required Size, and Contiguous Buffer Option Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager/GetStream.md Retrieves a new RecyclableMemoryStream with a specified tag and minimum capacity, with an option to use a single contiguous underlying buffer. This is beneficial when the initial size is known and `GetBuffer` will be called. ```csharp public RecyclableMemoryStream GetStream(string? tag, long requiredSize, bool asContiguousBuffer) ``` -------------------------------- ### RecyclableMemoryStreamManager.GetStream(Guid, string, long, bool) Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager/GetStream.md Retrieves a new RecyclableMemoryStream object with a specified tag and minimum capacity. Optionally attempts to use a single contiguous underlying buffer. ```APIDOC ## RecyclableMemoryStreamManager.GetStream(Guid id, string? tag, long requiredSize, bool asContiguousBuffer) ### Description Retrieve a new [`RecyclableMemoryStream`](../RecyclableMemoryStream.md) object with the given tag and at least the given capacity, possibly using a single contiguous underlying buffer. ### Method GET ### Endpoint /api/streams ### Parameters #### Path Parameters - **id** (Guid) - Required - A unique identifier which can be used to trace usages of the stream. - **tag** (string) - Optional - A tag which can be used to track the source of the stream. - **requiredSize** (long) - Required - The minimum desired capacity for the stream. - **asContiguousBuffer** (bool) - Required - Whether to attempt to use a single contiguous buffer. ### Request Example ```json { "id": "a1b2c3d4-e5f6-7890-1234-567890abcdef", "tag": "stream-source", "requiredSize": 1024, "asContiguousBuffer": true } ``` ### Response #### Success Response (200) - **RecyclableMemoryStream** (object) - A new RecyclableMemoryStream instance. #### Response Example ```json { "stream": "" } ``` ``` -------------------------------- ### RecyclableMemoryStream Constructors Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStream.md Initializes a new instance of the RecyclableMemoryStream class. There are multiple constructors available to suit different initialization needs. ```APIDOC ## RecyclableMemoryStream Constructors ### Description Initializes a new instance of the `RecyclableMemoryStream` class. ### Method Constructor ### Endpoint N/A ### Parameters (Details for each of the 6 constructors are not provided in the source text, but they exist.) ### Request Example N/A ### Response N/A ``` -------------------------------- ### GetStream with Tag and Required Size Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager/GetStream.md Retrieves a new RecyclableMemoryStream with a specified tag and a minimum required capacity. Use this when you know the approximate size needed for the stream. ```csharp public RecyclableMemoryStream GetStream(string? tag, long requiredSize) ``` -------------------------------- ### RecyclableMemoryStreamManager.Options.MaximumSmallPoolFreeBytes Property Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.Options/MaximumSmallPoolFreeBytes.md Gets or sets the maximum number of bytes to keep available in the small pool. Buffers returned to the pool beyond this limit will be garbage collected. The default value is 0. ```APIDOC ## RecyclableMemoryStreamManager.Options.MaximumSmallPoolFreeBytes Property ### Description Gets or sets the maximum number of bytes to keep available in the small pool. Buffers returned to the pool beyond this limit will be garbage collected. The default value is 0. ### Remarks Trying to return buffers to the pool beyond this limit will result in them being garbage collected. The default value is 0, but all users should set a reasonable value depending on your application's memory requirements. ### See Also * class [Options](../RecyclableMemoryStreamManager.Options.md) * namespace [Microsoft.IO](../../Microsoft.IO.RecyclableMemoryStream.md) ``` -------------------------------- ### Using Tags for Debugging Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/README.md Optionally provide a string tag to identify streams during debugging. This tag is a human-readable identifier. ```csharp using (var stream = manager.GetStream("Program.Main")) { stream.Write(sourceBuffer, 0, sourceBuffer.Length); } ``` -------------------------------- ### UsageReportEventArgs Class Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.UsageReportEventArgs.md Provides details about the UsageReportEventArgs class, including its properties and constructor. ```APIDOC ## class UsageReportEventArgs ### Description Arguments for the [`UsageReport`](./RecyclableMemoryStreamManager/UsageReport.md) event. ### Remarks Initializes a new instance of the [`UsageReportEventArgs`](./RecyclableMemoryStreamManager.UsageReportEventArgs.md) class. ### Properties #### Small Pool - **smallPoolInUseBytes** (long) - Bytes from the small pool currently in use. - **smallPoolFreeBytes** (long) - Bytes from the small pool currently available. #### Large Pool - **largePoolInUseBytes** (long) - Bytes from the large pool currently in use. - **largePoolFreeBytes** (long) - Bytes from the large pool currently available. ### See Also * class [RecyclableMemoryStreamManager](./RecyclableMemoryStreamManager.md) * namespace [Microsoft.IO](../Microsoft.IO.RecyclableMemoryStream.md) ``` -------------------------------- ### Log Memory Stream Finalization Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.Events/MemoryStreamFinalized.md This method is called when a recyclable memory stream is finalized. It logs the stream's GUID, tag, and allocation stack. Allocation stack logging is conditional on the RecyclableMemoryStreamManager.GenerateCallStacks setting. ```csharp public void MemoryStreamFinalized(Guid guid, string? tag, string? allocationStack) ``` -------------------------------- ### StreamLengthEventArgs Class Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.StreamLengthEventArgs.md Documentation for the StreamLengthEventArgs class, including its constructor and properties. ```APIDOC ## Class StreamLengthEventArgs Arguments for the `StreamLength` event. ### Remarks Initializes a new instance of the `StreamLengthEventArgs` class. ### Public Members #### Constructor * **StreamLengthEventArgs**() Arguments for the `StreamLength` event. #### Properties * **Length** (long) - Read-only Length of the stream. ### See Also * class `RecyclableMemoryStreamManager` * namespace `Microsoft.IO` ``` -------------------------------- ### Set MaximumLargePoolFreeBytes Source: https://github.com/microsoft/microsoft.io.recyclablememorystream/blob/master/docs/Microsoft.IO/RecyclableMemoryStreamManager.Options/MaximumLargePoolFreeBytes.md Configure the maximum number of bytes to keep available in the large pools. Buffers returned beyond this limit will be garbage collected. The default is 0, but a reasonable value should be set. ```csharp public long MaximumLargePoolFreeBytes { get; set; } ```