- Conversion of structure to byte array having the size S1.
- But the object consists of 2 structure of with same data as i say above (each size of structure S1), after conversion of object to byte array the size of byte array is more than 2*S1.
- why that have more size. how can we get that xtra size .
Loading
Vinoth RajendranPosted Jun 23, 2016, 5:22 AM
MounikaPosted Jun 23, 2016, 4:52 AM
Vinoth RajendranPosted Jun 23, 2016, 4:44 AM
This problem regarding byte alignment in the structure
You first structure contains 2 double values (total size 16) & second structure contains 3 int (total size 12)
3rd structure contains the both structure, in this case system allocate the size of 32 bit because the default alignment of the type is the size of its largest element in the structure in your case double is max
To fix this use the [StructLayout(LayoutKind.Sequential, Pack = 1)] , above the structure , then structure allocate memory only based on the data type in structure.
MounikaPosted Jun 23, 2016, 3:29 AM
MounikaPosted Jun 22, 2016, 9:26 AM
Vinoth RajendranPosted Jun 22, 2016, 3:57 AM