C# Класс ErrorProne.NET.Utils.StructSizeCalculator

Показать файл Открыть проект

Открытые методы

Метод Описание
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