Skip to content

Replace use of Marshal.SizeOf with sizeof for blittable structs #3218

Open
@vatsan-madhavan

Description

@vatsan-madhavan

dotnet/pinvoke#463 (comment)

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.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Enhancement RequestedProduct code improvement that does NOT require public API changes/additions

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions