Microsoft.IO.RecyclableMemoryStream
Manages pools of objects.
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 , the large pool contains buffers of various sizes, all
multiples/exponentials of (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.
Arguments for the event.
Unique ID for the stream.
Optional Tag for the event.
Requested stream size.
Actual stream size.
Initializes a new instance of the class.
Unique ID of the stream.
Tag of the stream.
The requested stream size.
The actual stream size.
Arguments for the event.
Unique ID for the stream.
Optional Tag for the event.
Stack where the stream was allocated.
Stack where stream was disposed.
Lifetime of the stream.
Initializes a new instance of the class.
Unique ID of the stream.
Tag of the stream.
Stack of original allocation.
Dispose stack.
Initializes a new instance of the class.
Unique ID of the stream.
Tag of the stream.
Lifetime of the stream
Stack of original allocation.
Dispose stack.
Arguments for the event.
Unique ID for the stream.
Optional Tag for the event.
Stack where the stream was allocated.
First dispose stack.
Second dispose stack.
Initializes a new instance of the class.
Unique ID of the stream.
Tag of the stream.
Stack of original allocation.
First dispose stack.
Second dispose stack.
Arguments for the event.
Unique ID for the stream.
Optional Tag for the event.
Stack where the stream was allocated.
Initializes a new instance of the class.
Unique ID of the stream.
Tag of the stream.
Stack of original allocation.
Arguments for the event.
Unique ID for the stream.
Optional Tag for the event.
Stack where ToArray was called.
Length of stack.
Initializes a new instance of the class.
Unique ID of the stream.
Tag of the stream.
Stack of ToArray call.
Length of stream.
Arguments for the event.
Unique ID for the stream.
Optional Tag for the event.
Original allocation stack.
Requested capacity.
Maximum capacity.
Initializes a new instance of the class.
Unique ID of the stream.
Tag of the stream.
Requested capacity.
Maximum stream capacity of the manager.
Original allocation stack.
Arguments for the event.
How many bytes are currently in use from the small pool.
Initializes a new instance of the class.
Number of bytes currently in use from the small pool.
Arguments for the events.
Unique ID for the stream.
Optional Tag for the event.
Whether the buffer was satisfied from the pool or not.
Required buffer size.
How many bytes are in use from the large pool.
If the buffer was not satisfied from the pool, and is turned on, then.
this will contain the callstack of the allocation request.
Initializes a new instance of the class.
Unique ID of the stream.
Tag of the stream.
Required size of the new buffer.
How many bytes from the large pool are currently in use.
Whether the buffer was satisfied from the pool or not.
Callstack of the allocation, if it wasn't pooled.
Arguments for the event.
Unique ID for the stream.
Optional Tag for the event.
Type of the buffer.
The reason this buffer was discarded.
Initializes a new instance of the class.
Unique ID of the stream.
Tag of the stream.
Type of buffer being discarded.
The reason for the discard.
Arguments for the event.
Length of the stream.
Initializes a new instance of the class.
Length of the strength.
Arguments for the event.
Bytes from the small pool currently in use.
Bytes from the small pool currently available.
Bytes from the large pool currently in use.
Bytes from the large pool currently available.
Initializes a new instance of the class.
Bytes from the small pool currently in use.
Bytes from the small pool currently available.
Bytes from the large pool currently in use.
Bytes from the large pool currently available.
ETW events for RecyclableMemoryStream.
Static log object, through which all events are written.
Type of buffer.
Small block buffer.
Large pool buffer.
The possible reasons for discarding a buffer.
Buffer was too large to be re-pooled.
There are enough free bytes in the pool.
Logged when a stream object is created.
A unique ID for this stream.
A temporary ID for this stream, usually indicates current usage.
Requested size of the stream.
Actual size given to the stream from the pool.
Logged when the stream is disposed.
A unique ID for this stream.
A temporary ID for this stream, usually indicates current usage.
Lifetime in milliseconds of the stream
Call stack of initial allocation.
Call stack of the dispose.
Logged when the stream is disposed for the second time.
A unique ID for this stream.
A temporary ID for this stream, usually indicates current usage.
Call stack of initial allocation.
Call stack of the first dispose.
Call stack of the second dispose.
Note: Stacks will only be populated if RecyclableMemoryStreamManager.GenerateCallStacks is true.
Logged when a stream is finalized.
A unique ID for this stream.
A temporary ID for this stream, usually indicates current usage.
Call stack of initial allocation.
Note: Stacks will only be populated if RecyclableMemoryStreamManager.GenerateCallStacks is true.
Logged when ToArray is called on a stream.
A unique ID for this stream.
A temporary ID for this stream, usually indicates current usage.
Call stack of the ToArray call.
Length of stream.
Note: Stacks will only be populated if RecyclableMemoryStreamManager.GenerateCallStacks is true.
Logged when the RecyclableMemoryStreamManager is initialized.
Size of blocks, in bytes.
Size of the large buffer multiple, in bytes.
Maximum buffer size, in bytes.
Logged when a new block is created.
Number of bytes in the small pool currently in use.
Logged when a new large buffer is created.
Requested size.
Number of bytes in the large pool in use.
Logged when a buffer is created that is too large to pool.
Unique stream ID.
A temporary ID for this stream, usually indicates current usage.
Size requested by the caller.
Call stack of the requested stream.
Note: Stacks will only be populated if RecyclableMemoryStreamManager.GenerateCallStacks is true.
Logged when a buffer is discarded (not put back in the pool, but given to GC to clean up).
Unique stream ID.
A temporary ID for this stream, usually indicates current usage.
Type of the buffer being discarded.
Reason for the discard.
Number of free small pool blocks.
Bytes free in the small pool.
Bytes in use from the small pool.
Number of free large pool blocks.
Bytes free in the large pool.
Bytes in use from the large pool.
Logged when a stream grows beyond the maximum capacity.
Unique stream ID
The requested capacity.
Maximum capacity, as configured by RecyclableMemoryStreamManager.
A temporary ID for this stream, usually indicates current usage.
Call stack for the capacity request.
Note: Stacks will only be populated if RecyclableMemoryStreamManager.GenerateCallStacks is true.
Maximum length of a single array.
See documentation at https://docs.microsoft.com/dotnet/api/system.array?view=netcore-3.1
Default block size, in bytes.
Default large buffer multiple, in bytes.
Default maximum buffer size, in bytes.
Initializes the memory manager with the default block/buffer specifications. This pool may have unbounded growth unless you modify and .
Initializes the memory manager with the default block/buffer specifications and maximum free bytes specifications.
Maximum number of bytes to keep available in the small pool before future buffers get dropped for garbage collection
Maximum number of bytes to keep available in the large pool before future buffers get dropped for garbage collection
is negative, or is negative.
Initializes the memory manager with the given block requiredSize. This pool may have unbounded growth unless you modify and .
Size of each block that is pooled. Must be > 0.
Each large buffer will be a multiple of this value.
Buffers larger than this are not pooled
is not a positive number,
or is not a positive number,
or is less than .
is not a multiple of .
Initializes the memory manager with the given block requiredSize.
Size of each block that is pooled. Must be > 0.
Each large buffer will be a multiple of this value.
Buffers larger than this are not pooled
Maximum number of bytes to keep available in the small pool before future buffers get dropped for garbage collection
Maximum number of bytes to keep available in the large pool before future buffers get dropped for garbage collection
is not a positive number,
or is not a positive number,
or is less than ,
or is negative,
or is negative.
is not a multiple of .
Initializes the memory manager with the given block requiredSize. This pool may have unbounded growth unless you modify and .
Size of each block that is pooled. Must be > 0.
Each large buffer will be a multiple/exponential of this value.
Buffers larger than this are not pooled
Switch to exponential large buffer allocation strategy
is not a positive number,
or is not a positive number,
or is less than .
is not a multiple/exponential of .
Initializes the memory manager with the given block requiredSize.
Size of each block that is pooled. Must be > 0.
Each large buffer will be a multiple/exponential of this value.
Buffers larger than this are not pooled.
Switch to exponential large buffer allocation strategy.
Maximum number of bytes to keep available in the small pool before future buffers get dropped for garbage collection.
Maximum number of bytes to keep available in the large pool before future buffers get dropped for garbage collection.
is not a positive number,
or is not a positive number,
or is less than ,
or is negative,
or is negative.
is not a multiple/exponential of .
The size of each block. It must be set at creation and cannot be changed.
All buffers are multiples/exponentials of this number. It must be set at creation and cannot be changed.
Use multiple large buffer allocation strategy. It must be set at creation and cannot be changed.
Use exponential large buffer allocation strategy. It must be set at creation and cannot be changed.
Gets the maximum buffer size.
Any buffer that is returned to the pool that is larger than this will be
discarded and garbage collected.
Number of bytes in small pool not currently in use.
Number of bytes currently in use by stream from the small pool.
Number of bytes in large pool not currently in use.
Number of bytes currently in use by streams from the large pool.
How many blocks are in the small pool.
How many buffers are in the large pool.
How many bytes of small free blocks to allow before we start dropping
those returned to us.
The default value is 0, meaning the pool is unbounded.
How many bytes of large free buffers to allow before we start dropping
those returned to us.
The default value is 0, meaning the pool is unbounded.
Maximum stream capacity in bytes. Attempts to set a larger capacity will
result in an exception.
A value of 0 indicates no limit.
Whether to save callstacks for stream allocations. This can help in debugging.
It should NEVER be turned on generally in production.
Whether dirty buffers can be immediately returned to the buffer pool.
When is called on a stream and creates a single large buffer, if this setting is enabled, the other blocks will be returned
to the buffer pool immediately.
Note when enabling this setting that the user is responsible for ensuring that any buffer previously
retrieved from a stream which is subsequently modified is not used after modification (as it may no longer
be valid).
Causes an exception to be thrown if is ever called.
Calling defeats the purpose of a pooled buffer. Use this property to discover code that is calling . If this is
set and is called, a NotSupportedException will be thrown.
Removes and returns a single block from the pool.
A byte[] array.
Returns a buffer of arbitrary size from the large buffer pool. This buffer
will be at least the requiredSize and always be a multiple/exponential of largeBufferMultiple.
The minimum length of the buffer.
Unique ID for the stream.
The tag of the stream returning this buffer, for logging if necessary.
A buffer of at least the required size.
Requested array size is larger than the maximum allowed.
Returns the buffer to the large pool.
The buffer to return.
Unique stream ID.
The tag of the stream returning this buffer, for logging if necessary.
is null.
buffer.Length is not a multiple/exponential of (it did not originate from this pool).
Returns the blocks to the pool.
Collection of blocks to return to the pool.
Unique Stream ID.
The tag of the stream returning these blocks, for logging if necessary.
is null.
contains buffers that are the wrong size (or null) for this memory manager.
Returns a block to the pool.
Block to return to the pool.
Unique Stream ID.
The tag of the stream returning this, for logging if necessary.
is null.
is the wrong size for this memory manager.
Retrieve a new MemoryStream object with no tag and a default initial capacity.
A MemoryStream.
Retrieve a new MemoryStream object with no tag and a default initial capacity.
A unique identifier which can be used to trace usages of the stream.
A MemoryStream.
Retrieve a new MemoryStream object with the given tag and a default initial capacity.
A tag which can be used to track the source of the stream.
A MemoryStream.
Retrieve a new MemoryStream object with the given tag and a default initial capacity.
A unique identifier which can be used to trace usages of the stream.
A tag which can be used to track the source of the stream.
A MemoryStream.
Retrieve a new MemoryStream object with the given tag and at least the given capacity.
A tag which can be used to track the source of the stream.
The minimum desired capacity for the stream.
A MemoryStream.
Retrieve a new MemoryStream object with the given tag and at least the given capacity.
A unique identifier which can be used to trace usages of the stream.
A tag which can be used to track the source of the stream.
The minimum desired capacity for the stream.
A MemoryStream.
Retrieve a new MemoryStream object with the given tag and at least the given capacity.
A unique identifier which can be used to trace usages of the stream.
A tag which can be used to track the source of the stream.
The minimum desired capacity for the stream.
A MemoryStream.
Retrieve a new MemoryStream object with the given tag and at least the given capacity, possibly using
a single contiguous underlying buffer.
Retrieving a MemoryStream which provides a single contiguous buffer can be useful in situations
where the initial size is known and it is desirable to avoid copying data between the smaller underlying
buffers to a single large one. This is most helpful when you know that you will always call
on the underlying stream.
A unique identifier which can be used to trace usages of the stream.
A tag which can be used to track the source of the stream.
The minimum desired capacity for the stream.
Whether to attempt to use a single contiguous buffer.
A MemoryStream.
Retrieve a new MemoryStream object with the given tag and at least the given capacity, possibly using
a single contiguous underlying buffer.
Retrieving a MemoryStream which provides a single contiguous buffer can be useful in situations
where the initial size is known and it is desirable to avoid copying data between the smaller underlying
buffers to a single large one. This is most helpful when you know that you will always call
on the underlying stream.
A unique identifier which can be used to trace usages of the stream.
A tag which can be used to track the source of the stream.
The minimum desired capacity for the stream.
Whether to attempt to use a single contiguous buffer.
A MemoryStream.
Retrieve a new MemoryStream object with the given tag and at least the given capacity, possibly using
a single contiguous underlying buffer.
Retrieving a MemoryStream which provides a single contiguous buffer can be useful in situations
where the initial size is known and it is desirable to avoid copying data between the smaller underlying
buffers to a single large one. This is most helpful when you know that you will always call
on the underlying stream.
A tag which can be used to track the source of the stream.
The minimum desired capacity for the stream.
Whether to attempt to use a single contiguous buffer.
A MemoryStream.
Retrieve a new MemoryStream object with the given tag and at least the given capacity, possibly using
a single contiguous underlying buffer.
Retrieving a MemoryStream which provides a single contiguous buffer can be useful in situations
where the initial size is known and it is desirable to avoid copying data between the smaller underlying
buffers to a single large one. This is most helpful when you know that you will always call
on the underlying stream.
A tag which can be used to track the source of the stream.
The minimum desired capacity for the stream.
Whether to attempt to use a single contiguous buffer.
A MemoryStream.
Retrieve a new MemoryStream object with the given tag and with contents copied from the provided
buffer. The provided buffer is not wrapped or used after construction.
The new stream's position is set to the beginning of the stream when returned.
A unique identifier which can be used to trace usages of the stream.
A tag which can be used to track the source of the stream.
The byte buffer to copy data from.
The offset from the start of the buffer to copy from.
The number of bytes to copy from the buffer.
A MemoryStream.
Retrieve a new MemoryStream object with the contents copied from the provided
buffer. The provided buffer is not wrapped or used after construction.
The new stream's position is set to the beginning of the stream when returned.
The byte buffer to copy data from.
A MemoryStream.
Retrieve a new MemoryStream object with the given tag and with contents copied from the provided
buffer. The provided buffer is not wrapped or used after construction.
The new stream's position is set to the beginning of the stream when returned.
A tag which can be used to track the source of the stream.
The byte buffer to copy data from.
The offset from the start of the buffer to copy from.
The number of bytes to copy from the buffer.
A MemoryStream.
Retrieve a new MemoryStream object with the given tag and with contents copied from the provided
buffer. The provided buffer is not wrapped or used after construction.
The new stream's position is set to the beginning of the stream when returned.
A unique identifier which can be used to trace usages of the stream.
A tag which can be used to track the source of the stream.
The byte buffer to copy data from.
A MemoryStream.
Retrieve a new MemoryStream object with the given tag and with contents copied from the provided
buffer. The provided buffer is not wrapped or used after construction.
The new stream's position is set to the beginning of the stream when returned.
A unique identifier which can be used to trace usages of the stream.
A tag which can be used to track the source of the stream.
The byte buffer to copy data from.
A MemoryStream.
Retrieve a new MemoryStream object with the contents copied from the provided
buffer. The provided buffer is not wrapped or used after construction.
The new stream's position is set to the beginning of the stream when returned.
The byte buffer to copy data from.
A MemoryStream.
Retrieve a new MemoryStream object with the contents copied from the provided
buffer. The provided buffer is not wrapped or used after construction.
The new stream's position is set to the beginning of the stream when returned.
The byte buffer to copy data from.
A MemoryStream.
Retrieve a new MemoryStream object with the given tag and with contents copied from the provided
buffer. The provided buffer is not wrapped or used after construction.
The new stream's position is set to the beginning of the stream when returned.
A tag which can be used to track the source of the stream.
The byte buffer to copy data from.
A MemoryStream.
Retrieve a new MemoryStream object with the given tag and with contents copied from the provided
buffer. The provided buffer is not wrapped or used after construction.
The new stream's position is set to the beginning of the stream when returned.
A tag which can be used to track the source of the stream.
The byte buffer to copy data from.
A MemoryStream.
Triggered when a new block is created.
Triggered when a new large buffer is created.
Triggered when a new stream is created.
Triggered when a stream is disposed.
Triggered when a stream is disposed of twice (an error).
Triggered when a stream is finalized.
Triggered when a stream is disposed to report the stream's length.
Triggered when a user converts a stream to array.
Triggered when a stream is requested to expand beyond the maximum length specified by the responsible RecyclableMemoryStreamManager.
Triggered when a buffer of either type is discarded, along with the reason for the discard.
Periodically triggered to report usage statistics.
MemoryStream implementation that deals with pooling and managing memory streams which use potentially large
buffers.
This class works in tandem with the to supply MemoryStream-derived
objects to callers, while avoiding these specific problems:
-
LOH allocations
Since all large buffers are pooled, they will never incur a Gen2 GC
-
Memory wasteA standard memory stream doubles its size when it runs out of room. This
leads to continual memory growth as each stream approaches the maximum allowed size.
-
Memory copying
Each time a MemoryStream grows, all the bytes are copied into new buffers.
This implementation only copies the bytes when is called.
-
Memory fragmentation
By using homogeneous buffer sizes, it ensures that blocks of memory
can be easily reused.
The stream is implemented on top of a series of uniformly-sized blocks. As the stream's length grows,
additional blocks are retrieved from the memory manager. It is these blocks that are pooled, not the stream
object itself.
The biggest wrinkle in this implementation is when is called. This requires a single
contiguous buffer. If only a single block is in use, then that block is returned. If multiple blocks
are in use, we retrieve a larger buffer from the memory manager. These large buffers are also pooled,
split by size--they are multiples/exponentials of a chunk size (1 MB by default).
Once a large buffer is assigned to the stream the small blocks are NEVER again used for this stream. All operations take place on the
large buffer. The large buffer can be replaced by a larger buffer from the pool as needed. All blocks and large buffers
are maintained in the stream until the stream is disposed (unless AggressiveBufferReturn is enabled in the stream manager).
A further wrinkle is what happens when the stream is longer than the maximum allowable array length under .NET. This is allowed
when only blocks are in use, and only the Read/Write APIs are used. Once a stream grows to this size, any attempt to convert it
to a single buffer will result in an exception. Similarly, if a stream is already converted to use a single larger buffer, then
it cannot grow beyond the limits of the maximum allowable array size.
Any method that modifies the stream has the potential to throw an OutOfMemoryException, either because
the stream is beyond the limits set in RecyclableStreamManager, or it would result in a buffer larger than
the maximum array size supported by .NET.
All of these blocks must be the same size.
This list is used to store buffers once they're replaced by something larger.
This is for the cases where you have users of this class that may hold onto the buffers longer
than they should and you want to prevent race conditions which could corrupt the data.
This is only set by GetBuffer() if the necessary buffer is larger than a single block size, or on
construction if the caller immediately requests a single large buffer.
If this field is non-null, it contains the concatenation of the bytes found in the individual
blocks. Once it is created, this (or a larger) largeBuffer will be used for the life of the stream.
Unique identifier for this stream across its entire lifetime.
Object has been disposed.
A temporary identifier for the current usage of this stream.
Object has been disposed.
Gets the memory manager being used by this stream.
Object has been disposed.
Callstack of the constructor. It is only set if is true,
which should only be in debugging situations.
Callstack of the call. It is only set if is true,
which should only be in debugging situations.
Initializes a new instance of the class.
The memory manager.
Initializes a new instance of the class.
The memory manager.
A unique identifier which can be used to trace usages of the stream.
Initializes a new instance of the class.
The memory manager.
A string identifying this stream for logging and debugging purposes.
Initializes a new instance of the class.
The memory manager.
A unique identifier which can be used to trace usages of the stream.
A string identifying this stream for logging and debugging purposes.
Initializes a new instance of the class.
The memory manager
A string identifying this stream for logging and debugging purposes.
The initial requested size to prevent future allocations.
Initializes a new instance of the class.
The memory manager.
A string identifying this stream for logging and debugging purposes.
The initial requested size to prevent future allocations.
Initializes a new instance of the class.
The memory manager.
A unique identifier which can be used to trace usages of the stream.
A string identifying this stream for logging and debugging purposes.
The initial requested size to prevent future allocations.
Initializes a new instance of the class.
The memory manager
A unique identifier which can be used to trace usages of the stream.
A string identifying this stream for logging and debugging purposes.
The initial requested size to prevent future allocations.
Initializes a new instance of the class.
The memory manager.
A unique identifier which can be used to trace usages of the stream.
A string identifying this stream for logging and debugging purposes.
The initial requested size to prevent future allocations.
An initial buffer to use. This buffer will be owned by the stream and returned to the memory manager upon Dispose.
The finalizer will be called when a stream is not disposed properly.
Failing to dispose indicates a bug in the code using streams. Care should be taken to properly account for stream lifetime.
Returns the memory used by this stream back to the pool.
Whether we're disposing (true), or being called by the finalizer (false).
Equivalent to Dispose.
Gets or sets the capacity.
Capacity is always in multiples of the memory manager's block size, unless
the large buffer is in use. Capacity never decreases during a stream's lifetime.
Explicitly setting the capacity to a lower value than the current value will have no effect.
This is because the buffers are all pooled by chunks and there's little reason to
allow stream truncation.
Writing past the current capacity will cause to automatically increase, until MaximumStreamCapacity is reached.
If the capacity is larger than int.MaxValue, then InvalidOperationException will be thrown. If you anticipate using
larger streams, use the property instead.
Object has been disposed.
Capacity is larger than int.MaxValue.
Returns a 64-bit version of capacity, for streams larger than int.MaxValue in length.
Gets the number of bytes written to this stream.
Object has been disposed.
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.
Gets the current position in the stream.
Object has been disposed.
A negative value was passed.
Stream is in large-buffer mode, but an attempt was made to set the position past the maximum allowed array length.
If the buffer has already been converted to a large buffer, then the maximum length (and thus position) is limited by the maximum allowed array length in .NET.
Whether the stream can currently read.
Whether the stream can currently seek.
Always false.
Whether the stream can currently write.
Returns a single buffer containing the contents of the stream.
The buffer may be longer than the stream length.
A byte[] buffer.
IMPORTANT: Doing a after calling GetBuffer invalidates the buffer. The old buffer is held onto
until is called, but the next time GetBuffer is called, a new buffer from the pool will be required.
Object has been disposed.
stream is too large for a contiguous buffer.
Asynchronously reads all the bytes from the current position in this stream and writes them to another stream.
The stream to which the contents of the current stream will be copied.
This parameter is ignored.
The token to monitor for cancellation requests.
A task that represents the asynchronous copy operation.
is .
Either the current stream or the destination stream is disposed.
The current stream does not support reading, or the destination stream does not support writing.
Similarly to MemoryStream's behavior, CopyToAsync will adjust the source stream's position by the number of bytes written to the destination stream, as a Read would do.
Notifies the stream that bytes were written to the buffer returned by or .
Seeks forward by bytes.
You must request a new buffer after calling Advance to continue writing more data and cannot write to a previously acquired buffer.
How many bytes to advance.
Object has been disposed.
is negative.
is larger than the size of the previously requested buffer.
IMPORTANT: Calling Write(), GetBuffer(), TryGetBuffer(), Seek(), GetLength(), Advance(),
or setting Position after calling GetMemory() invalidates the memory.
IMPORTANT: Calling Write(), GetBuffer(), TryGetBuffer(), Seek(), GetLength(), Advance(),
or setting Position after calling GetSpan() invalidates the span.
When callers to GetSpan() or GetMemory() request a buffer that is larger than the remaining size of the current block
this method return a temp buffer. When Advance() is called, that temp buffer is then copied into the stream.
Returns a sequence containing the contents of the stream.
A ReadOnlySequence of bytes.
IMPORTANT: Calling Write(), GetMemory(), GetSpan(), Dispose(), or Close() after calling GetReadOnlySequence() invalidates the sequence.
Object has been disposed.
Returns an ArraySegment that wraps a single buffer containing the contents of the stream.
An ArraySegment containing a reference to the underlying bytes.
Returns if a buffer can be returned; otherwise, .
Returns a new array with a copy of the buffer's contents. You should almost certainly be using combined with the to
access the bytes in this stream. Calling ToArray will destroy the benefits of pooled buffers, but it is included
for the sake of completeness.
Object has been disposed.
The current object disallows ToArray calls.
The length of the stream is too long for a contiguous array.
Reads from the current position into the provided buffer.
Destination buffer.
Offset into buffer at which to start placing the read bytes.
Number of bytes to read.
The number of bytes read.
buffer is null.
offset or count is less than 0.
offset subtracted from the buffer length is less than count.
Object has been disposed.
Reads from the specified position into the provided buffer.
Destination buffer.
Offset into buffer at which to start placing the read bytes.
Number of bytes to read.
Position in the stream to start reading from.
The number of bytes read.
is null.
or is less than 0.
subtracted from the buffer length is less than .
Object has been disposed.
Stream position is beyond int.MaxValue.
Reads from the specified position into the provided buffer.
Destination buffer.
Offset into buffer at which to start placing the read bytes.
Number of bytes to read.
Position in the stream to start reading from.
The number of bytes read.
is null.
or is less than 0.
subtracted from the buffer length is less than .
Object has been disposed.
Reads from the current position into the provided buffer.
Destination buffer.
The number of bytes read.
Object has been disposed.
Reads from the specified position into the provided buffer.
Destination buffer.
Position in the stream to start reading from.
The number of bytes read.
Object has been disposed.
Stream position is beyond int.MaxValue.
Reads from the specified position into the provided buffer.
Destination buffer.
Position in the stream to start reading from.
The number of bytes read.
Object has been disposed.
Writes the buffer to the stream.
Source buffer.
Start position.
Number of bytes to write.
buffer is null.
offset or count is negative.
buffer.Length - offset is not less than count.
Object has been disposed.
Writes the buffer to the stream.
Source buffer.
buffer is null.
Object has been disposed.
Returns a useful string for debugging. This should not normally be called in actual production code.
Writes a single byte to the current position in the stream.
byte value to write.
Object has been disposed.
Reads a single byte from the current position in the stream.
The byte at the current position, or -1 if the position is at the end of the stream.
Object has been disposed.
Reads a single byte from the specified position in the stream.
The position in the stream to read from.
The byte at the current position, or -1 if the position is at the end of the stream.
Object has been disposed.
Stream position is beyond int.MaxValue.
Reads a single byte from the specified position in the stream.
The position in the stream to read from.
The byte at the current position, or -1 if the position is at the end of the stream.
Object has been disposed.
Sets the length of the stream.
value is negative or larger than .
Object has been disposed.
Sets the position to the offset from the seek location.
How many bytes to move.
From where.
The new position.
Object has been disposed.
is larger than .
Invalid seek origin.
Attempt to set negative position.
Synchronously writes this stream's bytes to the argument stream.
Destination stream.
Important: This does a synchronous write, which may not be desired in some situations.
is null.
Object has been disposed.
Synchronously writes this stream's bytes, starting at offset, for count bytes, to the argument stream.
Destination stream.
Offset in source.
Number of bytes to write.
is null.
is less than 0, or + is beyond this 's length.
Object has been disposed.
Synchronously writes this stream's bytes, starting at offset, for count bytes, to the argument stream.
Destination stream.
Offset in source.
Number of bytes to write.
is null.
is less than 0, or + is beyond this 's length.
Object has been disposed.
Writes bytes from the current stream to a destination byte array.
Target buffer.
The entire stream is written to the target array.
> is null.
Object has been disposed.
Writes bytes from the current stream to a destination byte array.
Target buffer.
Offset in the source stream, from which to start.
Number of bytes to write.
> is null.
is less than 0, or + is beyond this stream's length.
Object has been disposed.
Writes bytes from the current stream to a destination byte array.
Target buffer.
Offset in the source stream, from which to start.
Number of bytes to write.
Offset in the target byte array to start writing
buffer is null
is less than 0, or + is beyond this stream's length.
is less than 0, or + is beyond the target 's length.
Object has been disposed.
Release the large buffer (either stores it for eventual release or returns it immediately).