Aligning to cache line and knowing the cache line size

前端 未结 7 1756
盖世英雄少女心
盖世英雄少女心 2020-12-12 10:07

To prevent false sharing, I want to align each element of an array to a cache line. So first I need to know the size of a cache line, so I assign each element that amount of

7条回答
  •  情书的邮戳
    2020-12-12 10:37

    If anyone is curious about how to do this easily in C++, I've built a library with a CacheAligned class which handles determining the cache line size as well as the alignment for your T object, referenced by calling .Ref() on your CacheAligned object. You can also use Aligned if you know the cache line size beforehand, or just want to stick with the very common value of 64 (bytes).

    https://github.com/NickStrupat/Aligned

提交回复
热议问题