Reading the definition of Marshal.SizeOf(). It says the following: The size returned is the size of the unmanaged object. The unmanaged and managed sizes of an object can differ. The size returned is the size of the unmanaged object. The unmanaged and managed sizes of an object can differ. This means that Marshal.SizeOf will return the definition size to you, but not the actual size allocated to the memeory, because there may be some extras for alignment?
For example:
struct MyStruct { char c; }
The size will be 1 byte for an unmanaged object (unmanaged size) if I use Marshal.SizeOf() , but there may be 2 or 4 bytes for a managed object (managed size) if I use sizeof( ). I'm right?
c #
5YrsLaterDBA
source share