Table of Contents

Interface IUnifiedMemoryPool

Namespace
DotCompute.Abstractions.Memory
Assembly
DotCompute.Abstractions.dll

Unified memory pool interface that replaces all duplicate memory pool interfaces. This is the ONLY memory pool interface in the entire solution.

public interface IUnifiedMemoryPool : IAsyncDisposable, IDisposable
Inherited Members
Extension Methods

Properties

Accelerator

Gets the accelerator this pool belongs to (if any).

IAccelerator? Accelerator { get; }

Property Value

IAccelerator

ActiveAllocationCount

Gets the number of active allocations.

int ActiveAllocationCount { get; }

Property Value

int

AllocatedSize

Gets the currently allocated size in bytes.

long AllocatedSize { get; }

Property Value

long

AvailableSize

Gets the available size in bytes.

long AvailableSize { get; }

Property Value

long

PoolId

Gets the unique pool identifier.

string PoolId { get; }

Property Value

string

Statistics

Gets pool statistics.

MemoryPoolStatistics Statistics { get; }

Property Value

MemoryPoolStatistics

TotalSize

Gets the total pool size in bytes.

long TotalSize { get; }

Property Value

long

Methods

AllocateAsync<T>(int, MemoryOptions, CancellationToken)

Allocates memory from the pool.

ValueTask<IUnifiedMemoryBuffer<T>> AllocateAsync<T>(int count, MemoryOptions options = MemoryOptions.None, CancellationToken cancellationToken = default) where T : unmanaged

Parameters

count int

The number of elements to allocate.

options MemoryOptions

Memory allocation options.

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask<IUnifiedMemoryBuffer<T>>

The allocated memory buffer.

Type Parameters

T

The element type.

AllocateRawAsync(long, MemoryOptions, CancellationToken)

Allocates raw memory from the pool.

ValueTask<IUnifiedMemoryBuffer> AllocateRawAsync(long sizeInBytes, MemoryOptions options = MemoryOptions.None, CancellationToken cancellationToken = default)

Parameters

sizeInBytes long

The size in bytes to allocate.

options MemoryOptions

Memory allocation options.

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask<IUnifiedMemoryBuffer>

The allocated memory buffer.

CleanupAsync(bool, CancellationToken)

Performs cleanup operations on the pool.

ValueTask CleanupAsync(bool aggressive = false, CancellationToken cancellationToken = default)

Parameters

aggressive bool

Whether to perform aggressive cleanup.

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask

A task representing the cleanup operation.

DefragmentAsync(CancellationToken)

Defragments the memory pool to reduce fragmentation.

ValueTask DefragmentAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask

A task representing the defragmentation operation.

GetStatisticsAsync(CancellationToken)

Gets accurate pool statistics asynchronously.

ValueTask<MemoryPoolStatistics> GetStatisticsAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask<MemoryPoolStatistics>

A task containing the pool statistics.

Remarks

This method queries the device for accurate memory information, which may take 1-10ms. For fast access, use the Statistics property.

OptimizeAsync(CancellationToken)

Optimizes the pool by resizing, defragmenting, and cleaning up.

ValueTask OptimizeAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask

A task representing the optimization operation.

Reset()

Resets the pool, releasing all allocations.

void Reset()

ResizeAsync(long, CancellationToken)

Resizes the pool to the specified size.

ValueTask ResizeAsync(long newSizeInBytes, CancellationToken cancellationToken = default)

Parameters

newSizeInBytes long

The new size in bytes.

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask

A task representing the resize operation.

ReturnAsync(IUnifiedMemoryBuffer, CancellationToken)

Returns memory to the pool.

ValueTask ReturnAsync(IUnifiedMemoryBuffer buffer, CancellationToken cancellationToken = default)

Parameters

buffer IUnifiedMemoryBuffer

The memory buffer to return.

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask

A task representing the return operation.

TryAllocate<T>(int, out IUnifiedMemoryBuffer<T>?, MemoryOptions)

Tries to allocate memory from the pool without waiting.

bool TryAllocate<T>(int count, out IUnifiedMemoryBuffer<T>? buffer, MemoryOptions options = MemoryOptions.None) where T : unmanaged

Parameters

count int

The number of elements to allocate.

buffer IUnifiedMemoryBuffer<T>

The allocated buffer if successful.

options MemoryOptions

Memory allocation options.

Returns

bool

True if allocation succeeded, false otherwise.

Type Parameters

T

The element type.