Skip to content
This repository has been archived by the owner on Jul 26, 2023. It is now read-only.

Replace our use of Marshal.SizeOf with C# sizeof keyword #475

Closed
AArnott opened this issue Jul 1, 2020 · 0 comments · Fixed by #493
Closed

Replace our use of Marshal.SizeOf with C# sizeof keyword #475

AArnott opened this issue Jul 1, 2020 · 0 comments · Fixed by #493
Assignees

Comments

@AArnott
Copy link
Collaborator

AArnott commented Jul 1, 2020

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.

Originally posted by @jkotas in #463

Since all our structs are (or should be) blittable, we should confirm each one and replace the slow method with the faster keyword.

@AArnott AArnott self-assigned this Jul 4, 2020
AArnott added a commit that referenced this issue Jul 4, 2020
`sizeof(T)` is much faster than `Marshal.SizeOf<T>`, but it can only be safely used when `T` is a blittable type. This means all members are value types and have no `MarshalAs` attribute on them. This rule is recursive for all members.

Closes #475
AArnott added a commit that referenced this issue Jul 4, 2020
`sizeof(T)` is much faster than `Marshal.SizeOf<T>`, but it can only be safely used when `T` is a blittable type. This means all members are value types and have no `MarshalAs` attribute on them. This rule is recursive for all members.

Closes #475
AArnott added a commit that referenced this issue Jul 4, 2020
`sizeof(T)` is much faster than `Marshal.SizeOf<T>`, but it can only be safely used when `T` is a blittable type. This means all members are value types and have no `MarshalAs` attribute on them. This rule is recursive for all members.

Closes #475
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant