Cache Line Alignment (Need clarification on article)

后端 未结 3 1154
青春惊慌失措
青春惊慌失措 2021-02-02 02:44

I\'ve recently encountered what I think is a false-sharing problem in my application, and I\'ve looked up Sutter\'s article on how to align my data to cache lines. He suggests t

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-02 02:58

    You can't have arrays of size 0, so 1 is required to make it compile. However, the current draft version of the spec says that such padding is unecessary; the compiler must pad up to the struct's alignment.

    Note also that this code is ill-formed if CACHE_LINE_SIZE is smaller than alignof(T). To fix this, you should probably use [[align(CACHE_LINE_SIZE), align(T)]], which will ensure that a smaller alignment is never picked.

提交回复
热议问题