Class PluginDisposableMemoryExtension
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
marshalPluginDisposableMemoryMarshal*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
marshalPluginDisposableMemoryMarshalA 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
selectorPluginDisposableMemoryExtension.MarshalToMemorySelectorDelegateA 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
TThe 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
memoryPluginDisposableMemoryMarshalA 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
TThe 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>)
Converts a PluginDisposableMemory<T> instance to a PluginDisposableMemoryMarshal struct.
public static ref PluginDisposableMemoryMarshal ToUnmanagedMarshal<T>(this PluginDisposableMemory<T> memory) where T : unmanaged
Parameters
memoryPluginDisposableMemory<T>The PluginDisposableMemory<T> instance to convert.
Returns
- PluginDisposableMemoryMarshal
A reference to a newly allocated PluginDisposableMemoryMarshal structure that represents the unmanaged memory.
Type Parameters
TThe 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.