Table of Contents

Class PluginDisposableMemoryExtension

Namespace
Hi3Helper.Plugin.Core
Assembly
Hi3Helper.Plugin.Core.dll

Provides extension methods for working with PluginDisposableMemory<T> and PluginDisposableMemoryMarshal objects, enabling conversions between managed and unmanaged memory.

public static class PluginDisposableMemoryExtension
Inheritance
PluginDisposableMemoryExtension
Inherited Members

Methods

FreeMarshal(PluginDisposableMemoryMarshal*)

Releases the unmanaged memory associated with the specified PluginDisposableMemoryMarshal.

public static void FreeMarshal(PluginDisposableMemoryMarshal* marshal)

Parameters

marshal PluginDisposableMemoryMarshal*

A reference to the PluginDisposableMemoryMarshal instance whose unmanaged memory is to be freed.

FreeMarshal(ref PluginDisposableMemoryMarshal)

Releases the unmanaged memory associated with the specified PluginDisposableMemoryMarshal.

public static void FreeMarshal(this ref PluginDisposableMemoryMarshal marshal)

Parameters

marshal PluginDisposableMemoryMarshal

A reference to the PluginDisposableMemoryMarshal instance whose unmanaged memory is to be freed.

ToManagedSpan<T>(MarshalToMemorySelectorDelegate)

Converts a delegate-based memory selector into a managed span of the specified unmanaged type.

public static PluginDisposableMemory<T> ToManagedSpan<T>(this PluginDisposableMemoryExtension.MarshalToMemorySelectorDelegate selector) where T : unmanaged

Parameters

selector PluginDisposableMemoryExtension.MarshalToMemorySelectorDelegate

A delegate that provides memory information, including the memory handle, length, allocation status, and disposability.

Returns

PluginDisposableMemory<T>

A PluginDisposableMemory<T> instance representing the managed span of memory.
Returns Empty if the memory is not allocated or the length is less than or equal to zero.

Type Parameters

T

The unmanaged type of the elements in the span.

Remarks

This method is designed for scenarios where unmanaged memory needs to be safely wrapped in a managed structure for further processing. The returned span can optionally be disposable, depending on the information provided by the selector.

ToManagedSpan<T>(ref PluginDisposableMemoryMarshal)

Converts the unmanaged memory represented by the PluginDisposableMemoryMarshal instance into a managed span of the specified type.

public static PluginDisposableMemory<T> ToManagedSpan<T>(this ref PluginDisposableMemoryMarshal memory) where T : unmanaged

Parameters

memory PluginDisposableMemoryMarshal

A reference to the PluginDisposableMemoryMarshal instance containing the unmanaged memory to convert.

Returns

PluginDisposableMemory<T>

A PluginDisposableMemory<T> instance representing the managed span of type T.

Type Parameters

T

The type of elements in the span. Must be an unmanaged type.

Remarks

The returned span provides access to the memory block represented by memory.
If memory is marked as disposable, the span will also manage its disposal.

ToUnmanagedMarshal<T>(PluginDisposableMemory<T>)

public static ref PluginDisposableMemoryMarshal ToUnmanagedMarshal<T>(this PluginDisposableMemory<T> memory) where T : unmanaged

Parameters

memory PluginDisposableMemory<T>

The PluginDisposableMemory<T> instance to convert.

Returns

PluginDisposableMemoryMarshal

A reference to a newly allocated PluginDisposableMemoryMarshal structure that represents the unmanaged memory.

Type Parameters

T

The type of the elements in the memory. Must be an unmanaged type.

Remarks

This method allocates unmanaged memory for the PluginDisposableMemoryMarshal structure and initializes it with the handle, length, and disposability state of the provided PluginDisposableMemory<T> instance.
The caller is responsible for ensuring proper disposal of the allocated memory to avoid memory leaks.