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
Methods
AlignAddress(void*, int)
Aligns a memory address to the specified boundary.
public static void* AlignAddress(void* address, int alignment)
Parameters
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
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
sourcevoid*The source memory pointer.
destinationvoid*The destination memory pointer.
byteCountnuintThe 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
sourceReadOnlySpan<T>The source span.
destinationSpan<T>The destination span.
Type Parameters
TThe 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
destinationvoid*The destination memory pointer.
valuebyteThe value to fill with.
byteCountnuintThe 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
destinationSpan<T>The destination span.
valueTThe value to fill with.
Type Parameters
TThe 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
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
ZeroMemory<T>(Span<T>)
Zeros out memory using generic types.
public static void ZeroMemory<T>(Span<T> destination) where T : unmanaged
Parameters
destinationSpan<T>The destination span.
Type Parameters
TThe element type.