[.net] Struct alignment in memory in .NET 2.0

Started by
1 comment, last by DrGUI 18 years, 9 months ago
I saw this on MSDN - don't know if everyone's aware...the JIT now seems to lay out your type members in the defined order rather than automatically re-ordering them!
Quote:While it may seem like a regression for the newer version of the Framework to increase the size of the type, it's actually expected behavior and a good thing that the JIT now respects the specified layout. If you'd prefer to let the JIT determine the best layout automatically (resulting in the same output as is currently generated by the 1.x JIT), you can explicitly mark your structure with a StructLayoutAttribute, specifying LayoutKind.Auto.
Here's the link Anyone want to comment before I add this attribute to my structs? [grin]
Advertisement
Quote:By default, the C#, Visual Basic .NET, and C++ compilers all apply a StructLayoutAttribute to structures, specifying a Sequential layout.


I think it's a good thing that the JIT now respects the layout specified by the application. However, I fail to see what good the C# compiler does us by automatically specifying Sequential instead of Auto layouts.
Yeah Holy Fuzz (cool name [smile]) - you want it to align all your field in size-ascending order or whatever to shrink their size and make them faster!

This topic is closed to new replies.

Advertisement