Skip to content

Why Nullable<byte> is aligned to 8 bytes instead of 2 bytes as short does? #12977

Closed
@yyjdelete

Description

@yyjdelete

Use System.Runtime.CompilerServices.Unsafe.SizeOf<T>() and ValueTuple to do the test, seems it's always the same on different version of .net.(x86 aligned to 4 bytes)
Don't know why it need such a big padding, and use 3 more times(1 more time for x86) memory than it actually needed.

Type Length
byte? 2
short 2
ValueTuple<byte?> 2
ValueTuple 2
ValueTuple<short, short> 4
ValueTuple<byte?, byte?> 16
ValueTuple<short, short, short> 8
ValueTuple<byte?, byte?, byte?> 24

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions