C# 클래스 ErrorProne.NET.Utils.StructSizeCalculator

파일 보기 프로젝트 열기: SergeyTeplyakov/ErrorProne.NET

공개 메소드들

메소드 설명
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:

비공개 메소드들

메소드 설명
GetSize ( Microsoft.CodeAnalysis.SemanticModel semanticModel, ITypeSymbol type, int &capacity, int &largestFieldSize, int &actualSize ) : void
TryGetPrimitiveSize ( ITypeSymbol type, int &size, int &largestFieldSize ) : bool

메소드 상세

ComputeStructSize() 공개 정적인 메소드

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
리턴 int