Strange Marshalling issue
Hi, I'm hitting a strange issue. My Handle_t type, which simply contains an Int32 is the same length as an Int32, as expected. However when it's included in another struct and it's size is checked, the size is incorrect.
See below code sample:
3 Replies
Welp, that was a quick fix that I didn't think of before. I just removed StructLayout from the Handle_t type altogether, and that fixed it. Now both of them are 8 bytes, as expected. I guess it layouted the internal fields of an Int32 too?
it's 6 because you said
Handle_t
is byte-aligned, not int-aligned, by writing Pack = 1
it means that the size of Test_t
does not have to be a multiple of 4
4 + 1 + 1 is 6, and it does not need to round to satisfy the alignment, so it remains 6
once you got rid of that, then Handle_t
is int-aligned, and the size is rounded up to the next multiple of 4Ah. Makes sense actually. Thanks for the explanation!