RecyclableMemoryStream.GetBuffer method

October 6, 2021 · View on GitHub

Returns a single buffer containing the contents of the stream. The buffer may be longer than the stream length.

public override byte[] GetBuffer()

Return Value

A byte[] buffer.

Exceptions

exceptioncondition
ObjectDisposedExceptionObject has been disposed.
OutOfMemoryExceptionstream is too large for a contiguous buffer.

Remarks

IMPORTANT: Doing a Write after calling GetBuffer invalidates the buffer. The old buffer is held onto until Dispose is called, but the next time GetBuffer is called, a new buffer from the pool will be required.

See Also