C# Class ErrorProne.NET.Utils.StructSizeCalculator

Afficher le fichier Open project: SergeyTeplyakov/ErrorProne.NET

Méthodes publiques

Méthode Description
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:

Private Methods

Méthode Description
GetSize ( Microsoft.CodeAnalysis.SemanticModel semanticModel, ITypeSymbol type, int &capacity, int &largestFieldSize, int &actualSize ) : void
TryGetPrimitiveSize ( ITypeSymbol type, int &size, int &largestFieldSize ) : bool

Method Details

ComputeStructSize() public static méthode

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:
public static ComputeStructSize ( this type, Microsoft.CodeAnalysis.SemanticModel semanticModel ) : int
type this
semanticModel Microsoft.CodeAnalysis.SemanticModel
Résultat int