✅ Marshal.SizeOf is not what I'm thinking
ChunkDataBackupWrapper.SIZE is one byte smaller than Marshal.SizeOf()
ChunkData: 40430 Marshal.SizeOf, 40430 SIZE
ChunkDataBackupWrapper: 40432 Marshal.SizeOf, 40432 SIZE
I'm trying to read https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.structlayoutattribute.pack?redirectedfrom=MSDN&view=net-7.0 but there's a lot of stuff that I can't wrap my head around.
"The alignment of the type is the size of its largest element (1, 2, 4, 8, etc., bytes) or the specified packing size, whichever is smaller."
"Byte fields align on 1-byte boundaries, Int16 fields align on 2-byte boundaries, and Int32 fields align on 4-byte boundaries."
1. I'm using bytes/bool everywhere, why didn't the second struct align to 1s?
2. Also is "volumeData" considered as an element of size "1" or size "35937"?
3. What's the rules for the size of the struct? I'm not sure I understand
StructLayoutAttribute.Pack Field (System.Runtime.InteropServices)
Controls the alignment of data fields of a class or structure in memory.
5 Replies
I'm using bytes/bool everywhere, why didn't the second struct align to 1s?this is your issue. a
bool
is 4 bytes when marshaledI'm using a weird engine, Quantum Photon and if you don't have [StructLayout.Explicit] it literally doesn't compile lol
I'll keep that in mind, thanks.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.