Marshal.SizeOf().
的定義如下:The size returned is the size of the unmanaged object. The unmanaged and managed sizes of an object can differ.
這是否意味着Marshal.SizeOf會返回您的定義大小,但不會返回實際的memeory分配的大小,因爲可能有一些用於對齊的填充?C#非託管對象的大小是多少?
例如:
struct MyStruct
{
char c;
}
大小將是非託管對象(非託管尺寸)1個字節,如果我使用Marshal.SizeOf()
也可以是用於被管理對象(管理的大小)2或4個字節,如果我使用sizeof(
) 。我對嗎?