ComputeStructSize ( this type, Microsoft.CodeAnalysis.SemanticModel semanticModel ) : int |
Computes size of the struct. This computation is not perfect, but could be good for the first time. Current algorythm was reversed engineered for sequential layout by set of test cases and here it is: CLR tries to pack members based on their size. If next item has larger size, then previous items are aligned to it (with empty space) and new item is aligned in memory: [1][1] // byte, byte => 2 [1 ][ 2 ] // byte, short => 4 [1 ][ 2 ][ 4 ] // byte, short, int => 8 [1 ][8 ] // byte, long => 16 [ 4 ][1][1][ 2 ] // int, byte, byte, short => 8 One caveat for composite fields: For nested composite field the same rule applied recursively: |
|