Why does struct alignment depend on whether a field type is primitive or user-defined?

后端 未结 4 831
天涯浪人
天涯浪人 2020-12-07 14:38

In Noda Time v2, we\'re moving to nanosecond resolution. That means we can no longer use an 8-byte integer to represent the whole range of time we\'re interested in. That ha

4条回答
  •  一整个雨季
    2020-12-07 15:06

    Just to add some data to the mix - I created one more type from the ones you had:

    struct RefAndTwoInt32Wrappers2
    {
        string text;
        TwoInt32Wrappers z;
    }
    

    The program writes out:

    RefAndTwoInt32Wrappers2: 16
    

    So it looks like the TwoInt32Wrappers struct aligns properly in the new RefAndTwoInt32Wrappers2 struct.

提交回复
热议问题