I already watched a session from Mario Hewardt that mentions a class containing an integer property takes 16 bytes of space. I'd like to know how the size of a simple following class can result in 16?
[StructLayout(LayoutKind.Sequential)]
public class MyClass
{
public int Age;
}
The problem is that the integer takes 4 bytes of space (right?) so where the heck those 12 other bytes come from? I've also used Marshal.SizeOf to get the class size which resulted in 4:
int n = Marshal.SizeOf(typeof(MyClass));
//n == 4
I've read this and it seems that the above class holds 8 bytes of internal data (what are these data anyway?), 4 byte for the int value, and 4 bytes of unused space. So if it takes 16 byte, why Marshal.SizeOf returns 4? and if it takes 4, where those 8 bytes are gone? I'm truly confused.