In this recipe, we will learn how to align data structures with cache lines. Data alignment can significantly affect the performance of your system, especially in the case of a multithreaded application that works in a multicore system.
Firstly, frequently accessing data that's used together is much faster if they live in the same cache line. If you program accesses variable A and then variable B consistently, a processor has to invalidate and reload its cache every time, if they are not in the same line.
Secondly, you don't want to keep data that's used independently by different threads in the same cache line. If the same cache line is modified by different CPU cores, this requires cache synchronization, which affects the overall performance of a multithreaded application that uses shared data, since in this scenario memory access...