Table of Contents

Class UnsafeMemoryOperations

Namespace
DotCompute.Memory
Assembly
DotCompute.Memory.dll

Provides high-performance unsafe memory operations with platform-specific optimizations. Includes zero-copy operations, proper memory alignment, and SIMD optimizations.

public static class UnsafeMemoryOperations
Inheritance
UnsafeMemoryOperations
Inherited Members

Fields

DefaultAlignment

The default alignment.

public const int DefaultAlignment = 32

Field Value

int

Methods

AlignAddress(void*, int)

Aligns a memory address to the specified boundary.

public static void* AlignAddress(void* address, int alignment)

Parameters

address void*

The memory address.

alignment int

The alignment boundary.

Returns

void*

The aligned address.

CalculatePadding(void*, int)

Calculates the padding needed to align an address.

public static int CalculatePadding(void* address, int alignment)

Parameters

address void*

The memory address.

alignment int

The alignment boundary.

Returns

int

The padding needed in bytes.

CopyMemory(void*, void*, nuint)

Copies memory from source to destination with optimal performance. Uses vectorized operations when possible.

public static void CopyMemory(void* source, void* destination, nuint byteCount)

Parameters

source void*

The source memory pointer.

destination void*

The destination memory pointer.

byteCount nuint

The number of bytes to copy.

CopyMemory<T>(ReadOnlySpan<T>, Span<T>)

Copies memory from source to destination using generic types.

public static void CopyMemory<T>(ReadOnlySpan<T> source, Span<T> destination) where T : unmanaged

Parameters

source ReadOnlySpan<T>

The source span.

destination Span<T>

The destination span.

Type Parameters

T

The element type.

FillMemory(void*, byte, nuint)

Fills memory with a specified value using vectorized operations.

public static void FillMemory(void* destination, byte value, nuint byteCount)

Parameters

destination void*

The destination memory pointer.

value byte

The value to fill with.

byteCount nuint

The number of bytes to fill.

FillMemory<T>(Span<T>, T)

Fills memory with a specified value using generic types.

public static void FillMemory<T>(Span<T> destination, T value) where T : unmanaged

Parameters

destination Span<T>

The destination span.

value T

The value to fill with.

Type Parameters

T

The element type.

IsAligned(void*, int)

Checks if a memory address is aligned to the specified boundary.

public static bool IsAligned(void* address, int alignment)

Parameters

address void*

The memory address.

alignment int

The alignment boundary.

Returns

bool

True if the address is aligned.

ZeroMemory(void*, nuint)

Zeros out memory using vectorized operations.

public static void ZeroMemory(void* destination, nuint byteCount)

Parameters

destination void*

The destination memory pointer.

byteCount nuint

The number of bytes to zero.

ZeroMemory<T>(Span<T>)

Zeros out memory using generic types.

public static void ZeroMemory<T>(Span<T> destination) where T : unmanaged

Parameters

destination Span<T>

The destination span.

Type Parameters

T

The element type.