IssueRaiser

allow references to structs to be stored in fields of ref structs

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

Posted by lucasmeijer on Nov 25, 2017, 11:40 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.4,500 issues0 comments

github (Software)

allow references to structs to be stored in fields of ref structs

lucasmeijerNov 25, 2017, 11:40 PM

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

Comments (0)

No comments yet. Start the discussion.

Comment on this issue