Closed kant2002 closed 3 years ago
Does similar possibility exists for Marshal.OffsetOf ?
Yes, look for Marshal.OffsetOf<T>(string fieldName)
.
For performance, it is even better to avoid calling the Marshal.SizeOf/Offset/StructureToPtr/PtrToStructure
methods and use blittable types instead. See https://docs.microsoft.com/en-us/dotnet/standard/native-interop/ . It is not always easy to refactor old code to avoid these Marshal
methods.
Thanks!
I learn from https://github.com/dotnet/corert/issues/5374#issuecomment-455706335 that
Marshal.SizeOf(typeof(TStruct))
should be replaced withMarshal.TypeOf<TStruct>()
. Does similar possibility exists forMarshal.OffsetOf
?