Table of Contents

Class DynamicMemoryStream

Namespace
Sdl3Sharp.IO
Assembly
Sdl3Sharp.dll

A stream that is backed by dynamically allocated memory

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

Constructors

DynamicMemoryStream()

Creates a new DynamicMemoryStream

public DynamicMemoryStream()

Properties

ChunkSize

Gets or sets the chunk size used for memory allocations

public uint ChunkSize { get; set; }

Property Value

uint

The chunk size used for memory allocations

Remarks

Memory will be allocated in multiples of this size, defaulting to 1024.

See Also

Memory

Gets or sets the pointer to the internal memory of the stream

public nint Memory { get; set; }

Property Value

nint

The pointer to the internal memory of the stream

Remarks

This property can be set to Zero to transfer ownership of the memory to the application, which should free the memory with Free(void*). If this is done, the next operation on the stream must be TryClose() or better Dispose(). Don't try to attempt this unless you really know what you are doing.

For a safer way to transfer ownership of the memory, use TryGetMemoryManagerAndDispose(out NativeMemoryManager?) instead.

See Also

Methods

TryGetMemoryManagerAndDispose(out NativeMemoryManager?)

Tries to transfer ownership of the internal memory of the stream to a NativeMemoryManager, disposing the stream in the process

public bool TryGetMemoryManagerAndDispose(out NativeMemoryManager? memoryManager)

Parameters

memoryManager NativeMemoryManager

The NativeMemoryManager that owns the memory, when this method returns true; otherwise, null

Returns

bool

true, if the memory ownership was successfully transferred to a new NativeMemoryManager; otherwise, false

Remarks

If this method returns true, the stream is disposed and no longer usable. The stream does not get disposed, if this method returns false.

The resulting NativeMemoryManager should be disposed when the memory it's managing is no longer needed. That also frees the allocated memory.