Table of Contents

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

source ReadOnlySpan<TFrom>

Source span.

Returns

ReadOnlySpan<TTo>

Reinterpreted read-only span.

Type Parameters

TFrom

Source type.

TTo

Target 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

source Span<TFrom>

Source span.

Returns

Span<TTo>

Reinterpreted span.

Type Parameters

TFrom

Source type.

TTo

Target 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

pointer void*

Pointer to the data.

length int

Length in elements.

Returns

ReadOnlySpan<T>

Read-only span wrapping the pointer.

Type Parameters

T

Element 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

pointer void*

Pointer to the data.

length int

Length in elements.

Returns

Span<T>

Span wrapping the pointer.

Type Parameters

T

Element 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

span Span<T>

Span to clear.

Type Parameters

T

Element 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

source ReadOnlySpan<T>

Source span.

destination Span<T>

Destination span.

Type Parameters

T

Element 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

left ReadOnlySpan<T>

First span.

right ReadOnlySpan<T>

Second span.

Returns

bool

True if spans are equal.

Type Parameters

T

Element 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

span Span<T>

Span to fill.

value T

Value to fill with.

Type Parameters

T

Element 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

span ReadOnlySpan<T>

Source span.

Returns

T

Read-only reference to the first element.

Type Parameters

T

Element 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

span Span<T>

Source span.

Returns

T

Reference to the first element.

Type Parameters

T

Element 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

source ReadOnlySpan<T>

Source span.

offset int

Offset in elements.

length int

Length in elements.

Returns

ReadOnlySpan<T>

Sliced read-only span.

Type Parameters

T

Element 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

source Span<T>

Source span.

offset int

Offset in elements.

length int

Length in elements.

Returns

Span<T>

Sliced span.

Type Parameters

T

Element type.