Why is KeyValuePair <int, long> 16 bytes?
KeyValuePair<int, int>: 8 bytes
KeyValuePair<long, long>: 16 bytes
KeyValuePair<long, int>: 16 bytes (!!)
KeyValuePair<int, long>: 16 bytes (!!)
I would expect the last two pairs to only require 8 (long) + 4 (int)= 12 bytes. Why do they occupy 16?
Sizes were determined using dynamic SizeOf emitted through ILGenerator, as discussed here: Size of the overall structure
+4
1 answer
This is due to alignment of the data structure . To quote a Wikipedia article:
, , - , . , , .
int - 4 KeyValuePair long int, . . "" 4 , , , .
, ints - , / padding, /. , ( int ) .
32- 64- , , .
" " , , .
+7