Open jaredpar opened 3 years ago
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
What about...?
Span<object> span = stackalloc object[5];
Which is sorta
struct Obj5
{
object o0;
object o1;
object o2;
object o3;
object o4;
}
Obj5 objs = default;
Span<object> span = CreateSpan(ref objs.o0, 5);
The stackalloc
primitive doesn't support reference types.
localloc
returning a byte*
pointer is obv problematic for a reference type; however if it was limited to a Span<ref type>
receiver and a fixed size rather than variable size then t could be translated to something closer to the safe fixed sized buffer proposal? e.g.
struct <Buffer>e__FixedBuffer_1024<T>
{
private T _e0;
private T _e1;
// _e2 ... _e1023
private T _e1024;
public ref T this[int index] => ref (uint)index <= 1024u ?
ref RefAdd<T>(ref _e0, index):
}
Not sure what the GC would make of referring only to an internal element of a stack struct (if it was sliced)
I think https://github.com/dotnet/runtime/issues/25423 is the proposal we should follow to improve stackalloc.
@jaredpar this is unlikely for 6 due to statics in interfaces work. Ok to move out?
Moving this to future, since this is moved out of .net 6.
Fore reference https://github.com/dotnet/runtime/issues/38743
This is a "User Story" to track the proposed improvements to low level struct performance improvements.
C# Language Features
ref
fields inref struct
types dotnet/csharplang#1147The feature proposal for both C# features is captured here
Related Runtime Requests:
ref
fields inref struct
dotnet/runtime#32060FixedSizBufferAttribute
proposal dotnet/runtime#12320