Data Structure Alignment - Allocating Memory Aligned To Cache Lines

Allocating Memory Aligned To Cache Lines

It would be beneficial to allocate memory aligned to cache lines. If an array is partitioned for more than one thread to operate on, having the sub-array boundaries unaligned to cache lines could lead to performance degradation. Here is an example to allocate memory (double array of size 10) aligned to cache of 64 bytes.

#include double *foo(void) { double *var;//create array of size 10 int ok; ok = posix_memalign((void**)&var, 64, 10*sizeof(double)); if(ok != 0) return NULL; return var; }

Read more about this topic:  Data Structure Alignment

Famous quotes containing the words memory and/or lines:

    “That you’re wavin’ from the backroads by the rivers of my memory ever smilin’
    Ever gentle on my mind.”
    —John Hartford (b.1937)

    “It is the Late city that first defies the land, contradicts Nature in the lines of its silhouette, denies all Nature. It wants to be something different from and higher than Nature. These high-pitched gables, these Baroque cupolas, spires, and pinnacles, neither are, nor desire to be, related with anything in Nature. And then begins the gigantic megalopolis, the city-as-world, which suffers nothing beside itself and sets about annihilating the country picture.”
    —Oswald Spengler (1880–1936)