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

Use Span<T> with fixed fields #2208

Closed
AArnott opened this issue Feb 9, 2019 · 2 comments
Closed

Use Span<T> with fixed fields #2208

AArnott opened this issue Feb 9, 2019 · 2 comments

Comments

@AArnott
Copy link
Contributor

AArnott commented Feb 9, 2019

From @AArnott on February 9, 2019 18:37

C# structs can have inline arrays like this:

unsafe struct Some
{
   private fixed byte something[4];
}

But then something is typed as byte*. With Span<T> we should have a safe alternative. Something like:

ref struct Some
{
    private fixed Span<byte> something[4];
}

This removes the unsafe keyword and lets us use Span<T> which embeds the length, making it safer.

Copied from original issue: dotnet/roslyn#33272

@tannergooding
Copy link
Member

This is very similar to the already championed fixed-sized buffers proposal: #1314 (which proposes supporting fixed-sized buffers of any type and relying on ref returning indexers).

@YairHalberstadt
Copy link
Contributor

Closing as effectively subsumed by #1314, and decided in #1502 that it's not currently under consideration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants