Open
Description
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.
There are many uses of Marshal.SizeOf
in the codebase - many of them likely for blittable types - that could be identified and updated to use faster sizeof
.
/cc @dotnet/dotnet-winforms - This probably applies to Winforms as well.