-
Notifications
You must be signed in to change notification settings - Fork 42
Description
Hi Sergey,
I have some good news: I noticed that you can avoid the per-field padding (i.e. alignment on pointer boundaries) for classes.
All you have to do is set the [StructLayout(LayoutKind.Sequential)] attribute on the class.
Although the attribute's name implies that it would only work on structs, the docs confirm that it "lets you control the physical layout of the data fields of a class or structure in memory".
Interestingly, the attribute's optional Pack field seems to have no effect on classes whatsoever, at least in the scenarios I've explored.
It stands to reason that, alternatively, the per-field padding could also be avoided with LayoutKind.Explicit, although I have not tested this.
Perhaps you could add some of this information to the corresponding section in your readme.