Table of Contents

Class MemoryAllocator

Namespace
DotCompute.Memory
Assembly
DotCompute.Memory.dll

A high-performance memory allocator that provides aligned memory allocation and efficient memory management. Supports both pinned and unpinned allocations with platform-specific optimizations.

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

Properties

TotalAllocatedBytes

Gets the total number of bytes allocated.

public long TotalAllocatedBytes { get; }

Property Value

long

TotalAllocations

Gets the total number of allocations made.

public long TotalAllocations { get; }

Property Value

long

TotalDeallocations

Gets the total number of deallocations made.

public long TotalDeallocations { get; }

Property Value

long

Methods

AllocateAligned<T>(int, int)

Allocates aligned memory for the specified type.

public IMemoryOwner<T> AllocateAligned<T>(int length, int alignment = 32) where T : unmanaged

Parameters

length int

The number of elements to allocate.

alignment int

The alignment requirement in bytes.

Returns

IMemoryOwner<T>

A memory owner for the allocated memory.

Type Parameters

T

The element type.

AllocatePinned<T>(int)

Allocates pinned memory for the specified type.

public IMemoryOwner<T> AllocatePinned<T>(int length) where T : unmanaged

Parameters

length int

The number of elements to allocate.

Returns

IMemoryOwner<T>

A memory owner for the pinned memory.

Type Parameters

T

The element type.

Allocate<T>(int)

Allocates memory using the system allocator.

public IMemoryOwner<T> Allocate<T>(int length) where T : unmanaged

Parameters

length int

The number of elements to allocate.

Returns

IMemoryOwner<T>

A memory owner for the allocated memory.

Type Parameters

T

The element type.

CreateUnifiedBuffer<T>(IUnifiedMemoryManager, int)

Creates a unified buffer using this allocator.

public IUnifiedMemoryBuffer<T> CreateUnifiedBuffer<T>(IUnifiedMemoryManager memoryManager, int length) where T : unmanaged

Parameters

memoryManager IUnifiedMemoryManager

The memory manager for device operations.

length int

The number of elements to allocate.

Returns

IUnifiedMemoryBuffer<T>

A unified buffer.

Type Parameters

T

The element type.

CreateUnifiedBuffer<T>(IUnifiedMemoryManager, ReadOnlySpan<T>)

Creates a unified buffer with initial data using this allocator.

public IUnifiedMemoryBuffer<T> CreateUnifiedBuffer<T>(IUnifiedMemoryManager memoryManager, ReadOnlySpan<T> data) where T : unmanaged

Parameters

memoryManager IUnifiedMemoryManager

The memory manager for device operations.

data ReadOnlySpan<T>

The initial data to populate the buffer with.

Returns

IUnifiedMemoryBuffer<T>

A unified buffer.

Type Parameters

T

The element type.

Dispose()

Releases all resources used by the MemoryAllocator.

public void Dispose()

GetStatistics()

Gets statistics about the memory allocator.

public MemoryAllocatorStatistics GetStatistics()

Returns

MemoryAllocatorStatistics

Memory allocator statistics.