allow references to structs to be stored in fields of ref structs
- Dominant language
- C#
- Stars
- 12.7k
- Forks
- 1.1k
- Avg merge
- 11h 1m
- Merged PRs (30d)
- 3
Description
Unity is a game engine that uses C# extensively.
We're in need of a way to have a struct that contains one or more pointers to other structs that we want to be able to read/write from/to. We do this with unsafe code today:
```C#
struct Color { float r,g,b; }
unsafe struct Group
{
Color* _color;
ref Color color => ref *_color;
}
```
But we would love to do this without unsafe code, and would like to suggest a feature where it's allowed to store references to structs in fields of ref structs, that can guarantee that these pointers don't escape onto the heap:
```C#
struct Color { float r,g,b; }
ref struct Group
{
ref Color color;
}
```
**EDIT** link to spec for this feature https://github.com/dotnet/csharplang/blob/main/proposals/low-level-struct-improvements.md
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.