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:

    ‘Tis of the essence of life here,
    Though we choose greatly, still to lack
    The lasting memory at all clear,
    That life has for us on the wrack
    Nothing but what we somehow chose;
    Thus are we wholly stripped of pride
    In the pain that has but one close,
    Bearing it crushed and mystified.
    Robert Frost (1874–1963)

    Your letter is come; it came indeed twelve lines ago, but I
    could not stop to acknowledge it before, & I am glad it did not
    arrive till I had completed my first sentence, because the
    sentence had been made since yesterday, & I think forms a very
    good beginning.
    Jane Austen (1775–1817)