dotnet icon indicating copy to clipboard operation
dotnet copied to clipboard

Span2D Constructor overload

Open sjMagstim opened this issue 1 year ago • 1 comments

Overview

A constructor for the Span2D<T> to create a 2D view over a Span<T>. Currently only arrays and pointers but I believe a Span would also be suitable. In fact, I think I can see an implementation already there, it's just marked as internal.

API breakdown

public readonly ref partial struct Span2D<T>
{
// ...
    public Span2D(Span<T> span, int height, int width) : this (span, 0, height, width, 0) {...}

    public Span2D(Span<T> span, int offset, int height, int width, int pitch) {...}
// ...
}

Usage example

Span<int> p = stackalloc int[9];
Span2D<int> span = new Span2D<int>(p, 3, 3);

Breaking change?

No

Alternatives

Span<int> span = stackalloc int[6];
Span2D<int> span2d = Span2D<int>.DangerousCreate(ref span[0], 2, 3, 0);
int* p = stackalloc int[6];
Span2D<int> span2d = new Span2D<int>(p, 2, 3, 0);

Additional context

No response

Help us help you

Yes, but only if others can assist

sjMagstim avatar Aug 29 '24 17:08 sjMagstim

Need this as well.

winstxnhdw avatar Oct 13 '24 22:10 winstxnhdw