2 ms·
>if you are a C# developer, honestly you don't care about low level code, or not having a garbage collector. You can go low level in C#**, just like Rust can a
by yyyk 1y ago
>if you are a C# developer, honestly you don't care about low level code, or not having a garbage collector.
You can go low level in C#**, just like Rust can avoid the borrow checker. It's just not a good tradeoff for most code in most games.
** value types/unsafe/pointers/stackalloc etc.
- neonsunset 1y agoStructs in C# or F# are not low-level per se, they simply are a choice and used frequently in gamedev. So is stackalloc because using it is just 'var things = (stackalloc Thing[5])' where the type of `things` is Span<Thing>. The keyword is a bit niche but it's very normal to see it in code that cares about avoiding allocations. Note that going more hands-on with these is not the same as violating memory safety - C# even has ref and byreflike struct lifetime analysis specifically to ensure this not an issue (https://em-tg.github.io/csborrow/ https://em-tg.github.io/csborrow/).
- yyyk 1y agoRight, it depends on how far one wants to go to avoid allocations. structs and spans are safe. But one can go even deeper and pin pointers and do Unsafe.AsPointer and get a de-facto (unsafe) union out of it.... >https://em-tg.github.io/csborrow/ https://em-tg.github.io/csborrow/ Oooh... I didn't know scoped refs existed.
- int_19h 1y agoIf you want an unsafe union, that's what StructLayout.Explicit and FieldOffset is for - a struct with all fields placed at offset 0 is exactly the same as a C union.