4 ms·
That link seems like it's about alignment rather than about arrays inside structures?
by tialaramex 4y ago
That link seems like it's about alignment rather than about arrays inside structures?
- pjmlp 4y agoNo, it is about alignment and packing, you use StructLayout attribute alongside LayoutKind and FieldOffsetAttribute. https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.layoutkind?source=recommendations&view=net-7.0 https://learn.microsoft.com/en-us/dotnet/api/system.runtime.... You main issue was how structures arrange their fields. Also regarding arrays and structs, as of C# 7 you can use fixed to declare static arrays inside structs, however these structs need to be marked as unsafe.
- tialaramex 4y ago> as of C# 7 you can use fixed to declare static arrays inside structs, however these structs need to be marked as unsafe. That is exactly what I was talking about.
- pjmlp 4y agoAh ok, somehow misunderstood that. However there are actually good reasons for it to be unsafe, although it is debatable if that alone should be it. One is due to the interactions with the GC, in case it moves the data and there are references to its elements, and stack size. One way to get around it is to use AoS instead of SoA, which is any the best option if performance is the ultimate goal.