Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Span2D Constructor overload #929

Open
sjMagstim opened this issue Aug 29, 2024 · 1 comment
Open

Span2D Constructor overload #929

sjMagstim opened this issue Aug 29, 2024 · 1 comment
Labels
feature request 📬 A request for new changes to improve functionality

Comments

@sjMagstim
Copy link

sjMagstim commented Aug 29, 2024

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 sjMagstim added the feature request 📬 A request for new changes to improve functionality label Aug 29, 2024
@winstxnhdw
Copy link

Need this as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request 📬 A request for new changes to improve functionality
Projects
None yet
Development

No branches or pull requests

2 participants