This is related to word alignment. Memory allocated by the structure/class members may be not continuously aligned, but aligned by some chunks, say, of 32-bit. You can control this alignment using attributes (see the links below), by if you don't, the default is used.
The difference between 64-bit and 32-bit default layout is harder to explain, but the reason is pretty obvious. The thing is: all the types use the same sizes in both kinds of architectures, except the size of the managed pointer: it is 64 or 32 bits, respectively. Therefore, structures or classes having
reverence-type instance fields are aligned differently.
Please see:
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.structlayoutattribute.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.fieldoffsetattribute.aspx[
^].
Please, find out the samples adding 4 or 8 extra bytes to the size of a data type by yourself. If you fail to do this exercise, show what have you tried and what were the results. Then we will be able to discuss it.
—SA