dotnet
dotnet copied to clipboard
Span2D Constructor overload
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
Need this as well.