3 ms·
Kind of -- there's 3 different layouts you can use for structs in .NET: "auto", "sequential", and "explicit". "auto" lets the JIT compiler organize the fields
by profquail 15y ago
Kind of -- there's 3 different layouts you can use for structs in .NET: "auto", "sequential", and "explicit".
"auto" lets the JIT compiler organize the fields in any order, with any padding bytes, etc. it wants to. This is the default, and changing it is basically a tradeoff between speed now (where the JIT compiler may not recognize where it can optimize something) and speed later (when we add a new optimization and your code automatically executes faster).
"sequential" requires the JIT compiler to layout the fields in the order they're defined, but it can add any padding bytes, etc. it wants to.
"explicit" forces you to specify the offset of each field, and forbids the compiler from re-ordering the fields or padding them in any way. It's rare to use this unless it's to handle interop'ing with a C library which uses some weird data structure as a parameter. You might get a speedup from using it in your GPU code, but since you've taken everything out of the hands of the compiler, there's little room for improvement/optimization.
Check out the docs on [StructLayout] for more info: http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.structlayoutattribute.aspx http://msdn.microsoft.com/en-us/library/system.runtime.inter...