Skip to content

Commit

Permalink
Add clarity for the large pool of buffers and the GetBuffer method pe…
Browse files Browse the repository at this point in the history
…rtaining to the .NET max array length (#370)
  • Loading branch information
campbell-reid-displayr authored Jan 17, 2025
1 parent badfc85 commit 7df2ef7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Read the change log [here](https://github.com/microsoft/Microsoft.IO.RecyclableM
The `RecyclableMemoryStreamManager` class maintains two separate pools of objects:

1. **Small Pool** - Holds small buffers (of configurable size). Used by default for all normal read/write operations. Multiple small buffers are chained together in the `RecyclableMemoryStream` class and abstracted into a single stream.
2. **Large Pool** - Holds large buffers, which are only used when you must have a single, contiguous buffer, such as when you plan to call `GetBuffer()`. It is possible to create streams larger than is possible to be represented by a single buffer because of .NET's array size limits.
2. **Large Pool** - Holds large buffers, which are only used when you must have a single, contiguous buffer, such as when you plan to call `GetBuffer()`. The `GetBuffer()` method is still bounded by .NET array size limits. If you need a larger stream than this, do not use this method.

A `RecyclableMemoryStream` starts out by using a small buffer, chaining additional ones as the stream capacity grows. Should you ever call `GetBuffer()` and the length is greater than a single small buffer's capacity, then the small buffers are converted to a single large buffer. You can also request a stream with an initial capacity; if that capacity is larger than the small pool block size, multiple blocks will be chained unless you call an overload with `asContiguousBuffer` set to true, in which case a single large buffer will be assigned from the start. If you request a capacity larger than the maximum poolable size, you will still get a stream back, but the buffers will not be pooled. (Note: This is not referring to the maximum array size. You can limit the poolable buffer sizes in `RecyclableMemoryStreamManager`)

Expand Down

0 comments on commit 7df2ef7

Please sign in to comment.