I'm a little unclear on something.
Decimal and DateTime are just structs, the Decimal type contains four Int32 fields, and because these are blittable a Decimal is indeed blittable.
DateTime is a struct too, it contains a single UInt64 field, because this is blittable I'd expect DateTime to be blittable but it isn't.
My understanding is that any struct or class that has LayoutKind.Sequential AND contains ONLY blittable fields, is itself blittable.
My research into this suggests that DateTime, although it is a struct, is not formatted with LayoutKind.Sequential and this is why it isn't blittable. It seems to have been defined with Auto layout and this is the reason it isn't blittable.
However, I don't know how or why this was done by MS, the C# language rules say that ALL structs have LayoutKind.Sequential applied BY DEFAULT.
Does anyone know more about this odd behaviour from DateTime?
Incidentally, you can test for blittable easily by just calling:
GCHandle pinStructure = GCHandle.Alloc(item, GCHandleType.Pinned);
If no exception is thrown, then the type of 'item' is a blittable type.
I suspect that they deliberately made DateTime non-blittable to avoid confusion with existing Win32 date time structs, making DateTime blittable migh lead people to believe they can marshal it to one
View Complete Post