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
ActiveAllocationCount
Gets the number of active allocations.
int ActiveAllocationCount { get; }
Property Value
AllocatedSize
Gets the currently allocated size in bytes.
long AllocatedSize { get; }
Property Value
AvailableSize
Gets the available size in bytes.
long AvailableSize { get; }
Property Value
PoolId
Gets the unique pool identifier.
string PoolId { get; }
Property Value
Statistics
Gets pool statistics.
MemoryPoolStatistics Statistics { get; }
Property Value
TotalSize
Gets the total pool size in bytes.
long TotalSize { get; }
Property Value
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
countintThe number of elements to allocate.
optionsMemoryOptionsMemory allocation options.
cancellationTokenCancellationTokenCancellation token.
Returns
- ValueTask<IUnifiedMemoryBuffer<T>>
The allocated memory buffer.
Type Parameters
TThe 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
sizeInByteslongThe size in bytes to allocate.
optionsMemoryOptionsMemory allocation options.
cancellationTokenCancellationTokenCancellation 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
aggressiveboolWhether to perform aggressive cleanup.
cancellationTokenCancellationTokenCancellation token.
Returns
- ValueTask
A task representing the cleanup operation.
DefragmentAsync(CancellationToken)
Defragments the memory pool to reduce fragmentation.
ValueTask DefragmentAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenCancellation token.
Returns
- ValueTask
A task representing the defragmentation operation.
GetStatisticsAsync(CancellationToken)
Gets accurate pool statistics asynchronously.
ValueTask<MemoryPoolStatistics> GetStatisticsAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenCancellation 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
cancellationTokenCancellationTokenCancellation 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
newSizeInByteslongThe new size in bytes.
cancellationTokenCancellationTokenCancellation 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
bufferIUnifiedMemoryBufferThe memory buffer to return.
cancellationTokenCancellationTokenCancellation 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
countintThe number of elements to allocate.
bufferIUnifiedMemoryBuffer<T>The allocated buffer if successful.
optionsMemoryOptionsMemory allocation options.
Returns
- bool
True if allocation succeeded, false otherwise.
Type Parameters
TThe element type.