Table of Contents

Class NumaMemoryManager

Namespace
DotCompute.Backends.CPU.Threading.NUMA
Assembly
DotCompute.Backends.CPU.dll

NUMA-aware memory allocation and management.

public sealed class NumaMemoryManager : IDisposable
Inheritance
NumaMemoryManager
Implements
Inherited Members
Extension Methods

Remarks

Initializes a new instance of the NumaMemoryManager class.

Constructors

NumaMemoryManager(NumaTopology)

NUMA-aware memory allocation and management.

public NumaMemoryManager(NumaTopology topology)

Parameters

topology NumaTopology

NUMA topology information.

Remarks

Initializes a new instance of the NumaMemoryManager class.

Properties

ActiveAllocations

Gets the number of active allocations.

public int ActiveAllocations { get; }

Property Value

int

TotalAllocatedBytes

Gets the total number of bytes allocated.

public long TotalAllocatedBytes { get; }

Property Value

long

Methods

AllocateAny(nuint)

Allocates memory on any available node.

public nint AllocateAny(nuint size)

Parameters

size nuint

Size in bytes.

Returns

nint

Pointer to allocated memory or IntPtr.Zero if allocation failed.

AllocateInterleaved(nuint, params int[])

Allocates memory using interleaved policy across multiple nodes.

public nint AllocateInterleaved(nuint size, params int[] nodeIds)

Parameters

size nuint

Size in bytes.

nodeIds int[]

Nodes to interleave across.

Returns

nint

Pointer to allocated memory or IntPtr.Zero if allocation failed.

AllocateOnNode(nuint, int)

Allocates memory on a specific NUMA node.

public nint AllocateOnNode(nuint size, int nodeId)

Parameters

size nuint

Size in bytes.

nodeId int

NUMA node ID.

Returns

nint

Pointer to allocated memory or IntPtr.Zero if allocation failed.

AllocatePreferred(nuint)

Allocates memory with automatic node selection based on current thread affinity.

public nint AllocatePreferred(nuint size)

Parameters

size nuint

Size in bytes.

Returns

nint

Pointer to allocated memory or IntPtr.Zero if allocation failed.

AllocateSystem(nuint)

Allocates memory using system default allocation.

public nint AllocateSystem(nuint size)

Parameters

size nuint

Size in bytes.

Returns

nint

Pointer to allocated memory or IntPtr.Zero if allocation failed.

CreateMemoryScope(int)

Creates a memory allocation scope that sets preferred node.

public IDisposable CreateMemoryScope(int nodeId)

Parameters

nodeId int

Node ID to prefer.

Returns

IDisposable

Disposable memory scope.

Dispose()

Disposes of the memory manager and frees all managed allocations.

public void Dispose()

Free(nint)

Frees previously allocated memory.

public bool Free(nint memoryAddress)

Parameters

memoryAddress nint

Address of memory to free.

Returns

bool

True if memory was freed successfully.

GetAllocationInfo(nint)

Gets allocation information for a memory address.

public AllocationInfo? GetAllocationInfo(nint memoryAddress)

Parameters

memoryAddress nint

Memory address.

Returns

AllocationInfo

Allocation information or null if not found.

GetMemoryStatistics()

Gets memory statistics for all allocations.

public MemoryStatistics GetMemoryStatistics()

Returns

MemoryStatistics

Memory allocation statistics.

MigrateMemory(nint, int)

Migrates memory from one node to another (if supported by platform).

public bool MigrateMemory(nint memoryAddress, int targetNodeId)

Parameters

memoryAddress nint

Memory address.

targetNodeId int

Target node ID.

Returns

bool

True if migration was successful or not needed.

SetPreferredNode(int)

Sets the preferred NUMA node for future allocations.

public void SetPreferredNode(int nodeId)

Parameters

nodeId int

Preferred node ID.