Memory alignment : how to use alignof / alignas?

后端 未结 4 535
星月不相逢
星月不相逢 2020-12-02 05:43

I work with shared memory right now.

I can\'t understand alignof and alignas.

cppreference is unclear : alignof return

4条回答
  •  伪装坚强ぢ
    2020-12-02 06:14

    Alignment is not padding (although padding is sometimes introduced to satisfy alignment requirements). It is an intrisic property of a C++ type. To put it in standardese (3.11[basic.align])

    Object types have alignment requirements (3.9.1, 3.9.2) which place restrictions on the addresses at which an object of that type may be allocated. An alignment is an implementation-defined integer value representing the number of bytes between successive addresses at which a given object can be allocated. An object type imposes an alignment requirement on every object of that type; stricter alignment can be requested using the alignment specifier (7.6.2).

提交回复
热议问题