Table of Contents

Class MemoryStream

Namespace
Sdl3Sharp.IO
Assembly
Sdl3Sharp.dll

A stream that is backed by a provided memory buffer

public sealed class MemoryStream : Stream, IDisposable
Inheritance
MemoryStream
Implements
Inherited Members
Extension Methods

Constructors

MemoryStream(NativeMemory)

Creates a new MemoryStream from a specified allocated memory buffer

public MemoryStream(NativeMemory nativeMemory)

Parameters

nativeMemory NativeMemory

The allocated memory buffer to use for the stream

Remarks

This pins the specified allocated memory buffer for the lifetime of the MemoryStream.

Exceptions

ArgumentException

nativeMemory is invalid

MemoryStream(Memory<byte>)

Creates a new MemoryStream from a specified Memory<T>

public MemoryStream(Memory<byte> memory)

Parameters

memory Memory<byte>

The memory to use for the stream

Remarks

This pins the specified Memory<T> for the lifetime of the MemoryStream.

Exceptions

InvalidOperationException

memory could not be pinned

MemoryStream(void*, nuint, MemoryStreamFreeFunc?)

Creates a new MemoryStream from a specified unmanaged memory and size

public MemoryStream(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 MemoryStream 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 MemoryStream is closed or disposed

Remarks

If the value of this property is null, the memory buffer will not be freed when the MemoryStream 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 MemoryStream was initialized with

public nint Memory { get; }

Property Value

nint

A pointer to the memory buffer that the MemoryStream was initialized with

See Also

Size

Gets the size, in bytes, of the memory buffer that the MemoryStream was initialized with

public nuint Size { get; }

Property Value

nuint

The size, in bytes, of the memory buffer that the MemoryStream 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