Today, Span\ ```c# Similarly for ReadOnlySpan\ cc: @VSadov, @davidfowl
// this is how it works today
Span
fixed (byte* pSpan = &span.DangerousGetPinnableReference()) {
...
}This proposal is to add language support that would allow for the following:
```c#
Span<byte> span = new byte[256];
fixed (byte* pSpan = span) {
...
}
@VSadov What do you think about this?
I am working on a more general proposal for a pattern-based pinning/fixed.
It should be able to answer the interop question for types such as ImmutableArray, Span, heapable Utf8String, and so on, in a more general way. There is clearly a need.
YESSS!!
FYI: Proposal for the Pattern based fixed statement - https://github.com/dotnet/csharplang/pull/1100
This has been fixed in https://github.com/dotnet/roslyn/pull/25624
Now spans can expose GetPinnableReference that returns a [readonly]ref to the first element, or nullptr if span is empty.
Most helpful comment
I am working on a more general proposal for a pattern-based pinning/fixed.
It should be able to answer the interop question for types such as
ImmutableArray,Span, heapableUtf8String, and so on, in a more general way. There is clearly a need.