Assuming such vector is std::vector<T, boost::alignment::aligned_allocator<T, 64>>
would be read/write accessed by several cores concurrently and having it allocated on a per-core basis (i.e. vector index 0 used by the CPU core 0 only, 1 by the core 1, and so on), if one wants to avoid false-sharing, the underlying T
here would have to be declared as either alignas(64)
or just ensuring to have it properly padded to a standard x86 cache line size (i.e. 64 bytes). But what if the vector's T
is std::unique_ptr<U>
? Does the same still hold and make sense, i.e. each vector item - in this case std::unique_ptr
- required to be 64 bytes in size?
If you want to be able to modify the pointer, then yes, you should ensure the pointers themselves are aligned. However, if the pointers are never changed while your parallel code is running, then they don't have to (it's fine to share read-only data among threads even if they share cache lines). But then you have to make sure U
is correctly aligned.
Note: don't assume 64 bytes cache line size, use std::hardware_destuctive_interference_size
instead.