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
TotalAllocations
Gets the total number of allocations made.
public long TotalAllocations { get; }
Property Value
TotalDeallocations
Gets the total number of deallocations made.
public long TotalDeallocations { get; }
Property Value
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
Returns
- IMemoryOwner<T>
A memory owner for the allocated memory.
Type Parameters
TThe element type.
AllocatePinned<T>(int)
Allocates pinned memory for the specified type.
public IMemoryOwner<T> AllocatePinned<T>(int length) where T : unmanaged
Parameters
lengthintThe number of elements to allocate.
Returns
- IMemoryOwner<T>
A memory owner for the pinned memory.
Type Parameters
TThe element type.
Allocate<T>(int)
Allocates memory using the system allocator.
public IMemoryOwner<T> Allocate<T>(int length) where T : unmanaged
Parameters
lengthintThe number of elements to allocate.
Returns
- IMemoryOwner<T>
A memory owner for the allocated memory.
Type Parameters
TThe 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
memoryManagerIUnifiedMemoryManagerThe memory manager for device operations.
lengthintThe number of elements to allocate.
Returns
- IUnifiedMemoryBuffer<T>
A unified buffer.
Type Parameters
TThe 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
memoryManagerIUnifiedMemoryManagerThe memory manager for device operations.
dataReadOnlySpan<T>The initial data to populate the buffer with.
Returns
- IUnifiedMemoryBuffer<T>
A unified buffer.
Type Parameters
TThe 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.