Class ZeroCopyOperations
- Namespace
- DotCompute.Memory
- Assembly
- DotCompute.Memory.dll
High-performance zero-copy operations using Span<T> and Memory<T>:
- Memory-mapped file operations for large datasets
- Pinned memory operations with automatic cleanup
- Vectorized memory operations with SIMD acceleration
- Unsafe pointer operations for maximum performance
- Interop-friendly memory layouts for native code
- Buffer slicing and views without allocation Target: Eliminate 95%+ of memory copies in hot paths
public static class ZeroCopyOperations
- Inheritance
-
ZeroCopyOperations
- Inherited Members
Methods
Cast<TFrom, TTo>(ReadOnlySpan<TFrom>)
Reinterprets a read-only span as a different type without copying.
public static ReadOnlySpan<TTo> Cast<TFrom, TTo>(this ReadOnlySpan<TFrom> source) where TFrom : unmanaged where TTo : unmanaged
Parameters
sourceReadOnlySpan<TFrom>Source span.
Returns
- ReadOnlySpan<TTo>
Reinterpreted read-only span.
Type Parameters
TFromSource type.
TToTarget type.
Cast<TFrom, TTo>(Span<TFrom>)
Reinterprets a span as a different type without copying.
public static Span<TTo> Cast<TFrom, TTo>(this Span<TFrom> source) where TFrom : unmanaged where TTo : unmanaged
Parameters
sourceSpan<TFrom>Source span.
Returns
- Span<TTo>
Reinterpreted span.
Type Parameters
TFromSource type.
TToTarget type.
CreateReadOnlySpan<T>(void*, int)
Creates a read-only span from a pointer and length.
public static ReadOnlySpan<T> CreateReadOnlySpan<T>(void* pointer, int length) where T : unmanaged
Parameters
Returns
- ReadOnlySpan<T>
Read-only span wrapping the pointer.
Type Parameters
TElement type.
CreateSpan<T>(void*, int)
Creates a span from a pointer and length with proper lifetime management.
public static Span<T> CreateSpan<T>(void* pointer, int length) where T : unmanaged
Parameters
Returns
- Span<T>
Span wrapping the pointer.
Type Parameters
TElement type.
FastClear<T>(Span<T>)
Clears a span using the fastest available method.
public static void FastClear<T>(this Span<T> span) where T : unmanaged
Parameters
spanSpan<T>Span to clear.
Type Parameters
TElement type.
FastCopy<T>(ReadOnlySpan<T>, Span<T>)
Copies data between spans using the fastest available method.
public static void FastCopy<T>(this ReadOnlySpan<T> source, Span<T> destination) where T : unmanaged
Parameters
sourceReadOnlySpan<T>Source span.
destinationSpan<T>Destination span.
Type Parameters
TElement type.
FastEquals<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)
Compares two spans for equality using optimized comparison.
public static bool FastEquals<T>(this ReadOnlySpan<T> left, ReadOnlySpan<T> right) where T : unmanaged
Parameters
leftReadOnlySpan<T>First span.
rightReadOnlySpan<T>Second span.
Returns
- bool
True if spans are equal.
Type Parameters
TElement type.
FastFill<T>(Span<T>, T)
Fills a span with a value using vectorized operations when possible.
public static void FastFill<T>(this Span<T> span, T value) where T : unmanaged
Parameters
spanSpan<T>Span to fill.
valueTValue to fill with.
Type Parameters
TElement type.
GetReference<T>(ReadOnlySpan<T>)
Gets a read-only reference to the first element of a span.
public static ref readonly T GetReference<T>(this ReadOnlySpan<T> span)
Parameters
spanReadOnlySpan<T>Source span.
Returns
- T
Read-only reference to the first element.
Type Parameters
TElement type.
GetReference<T>(Span<T>)
Gets a reference to the first element of a span for unsafe operations.
public static ref T GetReference<T>(this Span<T> span)
Parameters
spanSpan<T>Source span.
Returns
- T
Reference to the first element.
Type Parameters
TElement type.
UnsafeSlice<T>(ReadOnlySpan<T>, int, int)
Creates a zero-copy read-only slice without bounds checking in release builds.
public static ReadOnlySpan<T> UnsafeSlice<T>(this ReadOnlySpan<T> source, int offset, int length)
Parameters
sourceReadOnlySpan<T>Source span.
offsetintOffset in elements.
lengthintLength in elements.
Returns
- ReadOnlySpan<T>
Sliced read-only span.
Type Parameters
TElement type.
UnsafeSlice<T>(Span<T>, int, int)
Creates a zero-copy slice of a span without bounds checking in release builds.
public static Span<T> UnsafeSlice<T>(this Span<T> source, int offset, int length)
Parameters
Returns
- Span<T>
Sliced span.
Type Parameters
TElement type.