Table of Contents

Class ReadOnlyMemoryStream

Namespace
Sdl3Sharp.IO
Assembly
Sdl3Sharp.dll

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)

public ReadOnlyMemoryStream(ReadOnlyNativeMemory nativeMemory)

Parameters

nativeMemory ReadOnlyNativeMemory

The 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

nativeMemory is invalid

ReadOnlyMemoryStream(ReadOnlyMemory<byte>)

Creates a new ReadOnlyMemoryStream from a specified ReadOnlyMemory<T>

public ReadOnlyMemoryStream(ReadOnlyMemory<byte> memory)

Parameters

memory ReadOnlyMemory<byte>

The memory to use for the stream

Remarks

This pins the specified ReadOnlyMemory<T> for the lifetime of the ReadOnlyMemoryStream.

Exceptions

InvalidOperationException

memory could 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

mem void*

A pointer to the unmanaged memory to use for the stream

size nuint

The size of the unmanaged memory

freeFunc MemoryStreamFreeFunc

An 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

disposing bool

A value indicating whether the call came from a call to Dispose() or from the finalizer

close bool

A value indicating whether the stream should be closed

Remarks

This method is not threadsafe.

See Also