Table of Contents

Class CpuMemoryBuffer

Namespace
DotCompute.Core.Memory
Assembly
DotCompute.Core.dll

CPU memory buffer implementation.

public sealed class CpuMemoryBuffer : IUnifiedMemoryBuffer, IAsyncDisposable, IDisposable
Inheritance
CpuMemoryBuffer
Implements
Inherited Members
Extension Methods

Constructors

CpuMemoryBuffer(long, MemoryOptions)

Initializes a new instance of the CpuMemoryBuffer class.

public CpuMemoryBuffer(long sizeInBytes, MemoryOptions options)

Parameters

sizeInBytes long

The size in bytes.

options MemoryOptions

The options.

Properties

IsDisposed

Gets or sets a value indicating whether disposed.

public bool IsDisposed { get; }

Property Value

bool

The is disposed.

Options

Gets or sets the options.

public MemoryOptions Options { get; }

Property Value

MemoryOptions

The options.

SizeInBytes

Gets or sets the size in bytes.

public long SizeInBytes { get; }

Property Value

long

The size in bytes.

State

Gets or sets the state.

public BufferState State { get; set; }

Property Value

BufferState

The state.

Methods

CopyFromAsync<T>(ReadOnlyMemory<T>, long, CancellationToken)

Copies data from source memory to this CPU buffer with offset support.

public ValueTask CopyFromAsync<T>(ReadOnlyMemory<T> source, long offset, CancellationToken cancellationToken = default) where T : unmanaged

Parameters

source ReadOnlyMemory<T>

Source data to copy from.

offset long

Offset into this buffer in bytes.

cancellationToken CancellationToken

Cancellation token for the operation.

Returns

ValueTask

Completed task when copy finishes.

Type Parameters

T

Type of elements to copy.

CopyFromHostAsync<T>(ReadOnlyMemory<T>, long, CancellationToken)

Gets copy from host asynchronously.

public ValueTask CopyFromHostAsync<T>(ReadOnlyMemory<T> source, long offset = 0, CancellationToken cancellationToken = default) where T : unmanaged

Parameters

source ReadOnlyMemory<T>

The source.

offset long

The offset.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

The result of the operation.

Type Parameters

T

The T type parameter.

CopyToAsync<T>(Memory<T>, long, CancellationToken)

Copies data from this CPU buffer to destination memory with offset support.

public ValueTask CopyToAsync<T>(Memory<T> destination, long offset, CancellationToken cancellationToken = default) where T : unmanaged

Parameters

destination Memory<T>

Destination memory to copy to.

offset long

Offset into this buffer in bytes.

cancellationToken CancellationToken

Cancellation token for the operation.

Returns

ValueTask

Completed task when copy finishes.

Type Parameters

T

Type of elements to copy.

CopyToHostAsync<T>(Memory<T>, long, CancellationToken)

Gets copy to host asynchronously.

public ValueTask CopyToHostAsync<T>(Memory<T> destination, long offset = 0, CancellationToken cancellationToken = default) where T : unmanaged

Parameters

destination Memory<T>

The destination.

offset long

The offset.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

The result of the operation.

Type Parameters

T

The T type parameter.

Dispose()

Performs dispose.

public void Dispose()

DisposeAsync()

Gets dispose asynchronously.

public ValueTask DisposeAsync()

Returns

ValueTask

The result of the operation.