Marshal.SizeOf returns the size of the unmanaged view of the struct. sizeof returns the size of the managed view of the struct.
Unmanaged and managed views are identical for the blittable structs. It is better to use sizeof instead of Marshal.SizeOf for blittable structs. They return the same number and sizeof is much cheaper.
Marshal.SizeOf
returns the size of the unmanaged view of the struct.sizeof
returns the size of the managed view of the struct.Unmanaged and managed views are identical for the blittable structs. It is better to use
sizeof
instead ofMarshal.SizeOf
for blittable structs. They return the same number andsizeof
is much cheaper.Originally posted by @jkotas in https://github.com/dotnet/pinvoke/pull/463
Since all our structs are (or should be) blittable, we should confirm each one and replace the slow method with the faster keyword.