Class ReadOnlyMemoryStream
A stream that is backed by a provided read-only memory buffer
public sealed class ReadOnlyMemoryStream : Stream, IDisposable
- Inheritance
-
ReadOnlyMemoryStream
- Implements
- Inherited Members
- Extension Methods
Constructors
ReadOnlyMemoryStream(ReadOnlyNativeMemory)
Creates a new ReadOnlyMemoryStream from a specified allocated read-only memory buffer
public ReadOnlyMemoryStream(ReadOnlyNativeMemory nativeMemory)
Parameters
nativeMemoryReadOnlyNativeMemoryThe allocated read-only memory buffer to use for the stream
Remarks
This pins the specified allocated read-only memory buffer for the lifetime of the ReadOnlyMemoryStream.
Exceptions
- ArgumentException
nativeMemoryis invalid
ReadOnlyMemoryStream(ReadOnlyMemory<byte>)
Creates a new ReadOnlyMemoryStream from a specified ReadOnlyMemory<T>
public ReadOnlyMemoryStream(ReadOnlyMemory<byte> memory)
Parameters
memoryReadOnlyMemory<byte>The memory to use for the stream
Remarks
This pins the specified ReadOnlyMemory<T> for the lifetime of the ReadOnlyMemoryStream.
Exceptions
- InvalidOperationException
memorycould not be pinned
ReadOnlyMemoryStream(void*, nuint, MemoryStreamFreeFunc?)
Creates a new ReadOnlyMemoryStream from a specified unmanaged memory and size
public ReadOnlyMemoryStream(void* mem, nuint size, MemoryStreamFreeFunc? freeFunc = null)
Parameters
memvoid*A pointer to the unmanaged memory to use for the stream
sizenuintThe size of the unmanaged memory
freeFuncMemoryStreamFreeFuncAn optional delegate that is called to free the unmanaged memory when the stream is closed or disposed
Remarks
If freeFunc is unset or null, the unmanaged memory will not be freed when the stream is closed or disposed.
This parameter is reflected by the FreeFunc property. Changing the value of the FreeFunc property after construction also changes the automatic freeing behavior.
Properties
FreeFunc
Gets or sets a delegate that will be called to free the memory buffer when the ReadOnlyMemoryStream is closed or disposed
public MemoryStreamFreeFunc? FreeFunc { get; set; }
Property Value
- MemoryStreamFreeFunc
A delegate that will be called to free the memory buffer when the ReadOnlyMemoryStream is closed or disposed
Remarks
If the value of this property is null, the memory buffer will not be freed when the ReadOnlyMemoryStream is closed or disposed.
Changing the value of this property will also change the automatic freeing behavior.
Memory
Gets a pointer to the memory buffer that the ReadOnlyMemoryStream was initialized with
public nint Memory { get; }
Property Value
- nint
A pointer to the memory buffer that the ReadOnlyMemoryStream was initialized with
- See Also
Size
Gets the size, in bytes, of the memory buffer that the ReadOnlyMemoryStream was initialized with
public long Size { get; }
Property Value
- long
The size, in bytes, of the memory buffer that the ReadOnlyMemoryStream was initialized with
- See Also
Methods
Dispose(bool, bool)
Disposes the stream
protected override void Dispose(bool disposing, bool close)
Parameters
disposingboolA value indicating whether the call came from a call to Dispose() or from the finalizer
closeboolA value indicating whether the stream should be closed
Remarks
This method is not threadsafe.
- See Also
-
TryClose()