Skip to content

字节对齐导致体积超出预期: 对于Product实现,推荐自行添加StructLayout,对于预定义类型,修改泛型顺序可有效缓解 #5

Description

@IksRain

暂时不考虑修复,我不清楚这样是否会对性能有影响

[UnionImpl]
partial struct Result(long a,byte b); // sizeof(Result) == 24,byte+long+byte

可以使用

[UnionImpl]
[StructLayout(LayoutKind.Sequential,Pack = 1)]
partial struct Result(long a,byte b);   // sizeof(Result) ==10

对于预定义类型,可以使用

Union<byte,long>  // sizeof(Union<byte,long>) ==16

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions