Table of Contents

Class UnmanagedMemoryManager<T>

Namespace
NumSharp.Backends.Unmanaged
Assembly
NumSharp.dll

Presents a block of UNMANAGED memory as a Memory<T> / ReadOnlyMemory<T> WITHOUT taking ownership or a reference on the memory holder — the backing of Memory<T>() / ReadOnlyMemory<T>().

It is deliberately unsafe: it stores only a raw pointer, so it does NOT root the NDArray's ARC-counted buffer. A live Memory<T> keeps THIS manager object alive (a managed reference the Memory struct holds), but nothing here keeps the NDArray's unmanaged buffer alive. If the source NDArray is disposed or garbage-collected while a Memory<T> handed out here is still in use, the pointer dangles and every read/write corrupts memory. Keep the NDArray alive (side by side) for the entire lifetime of the Memory<T>.

public sealed class UnmanagedMemoryManager<T> : MemoryManager<T>, IMemoryOwner<T>, IDisposable, IPinnable where T : unmanaged

Type Parameters

T

An unmanaged element type; must match the NDArray's element type.

Inheritance
UnmanagedMemoryManager<T>
Implements
Inherited Members

Constructors

UnmanagedMemoryManager(void*, int)

public UnmanagedMemoryManager(void* pointer, int length)

Parameters

pointer void*

Pointer to the first element (the NDArray's logical element 0).

length int

Element count (must fit int — a Memory<T> limit).

UnmanagedMemoryManager(T*, int)

public UnmanagedMemoryManager(T* pointer, int length)

Parameters

pointer T*

Pointer to the first element (the NDArray's logical element 0).

length int

Element count (must fit int — a Memory<T> limit).

Methods

Dispose(bool)

No-op — this manager owns nothing; the NDArray owns the buffer.

protected override void Dispose(bool disposing)

Parameters

disposing bool

GetSpan()

The span over the unmanaged block. Aliases — no copy.

public override Span<T> GetSpan()

Returns

Span<T>

Pin(int)

Returns a handle over the raw pointer. The memory is already unmanaged and fixed, so no GCHandle is taken and no GC pin is needed — this is a plain pointer wrap.

public override MemoryHandle Pin(int elementIndex = 0)

Parameters

elementIndex int

Returns

MemoryHandle

Unpin()

No-op — nothing was pinned (the memory is unmanaged and does not move).

public override void Unpin()