title: How and when to align to cache line size?
body: <p>In Dmitry Vyukov's excellent bounded mpmc queue written in C++
  See: <a href="http://www.1024cores.net/home/lock-free-algorithms/queues/bounded-mpmc-queue">http://www.1024cores.net/home/lock-free-algorithms/queues/bounded-mpmc-queue</a></p>
  
  <p>He adds some padding variables.  I presume this is to make it align to a cache line for performance.  </p>
  
  <p>I have some questions.</p>
  
  <ol>
  <li>Why is it done in this way?  </li>
  <li>Is it a portable method that will
  always work </li>
  <li>In what cases would it be best to use <code>__attribute__
  ((aligned (64)))</code> instead. </li>
  <li><p>why would padding before a buffer pointer help with performance? isn't just the pointer loaded into the cache so it's really only the size of a pointer?</p>
  
  <pre><code>static size_t const     cacheline_size = 64;
  typedef char            cacheline_pad_t [cacheline_size];
  
  cacheline_pad_t         pad0_;
  cell_t* const           buffer_;
  size_t const            buffer_mask_;
  cacheline_pad_t         pad1_;
  std::atomic&lt;size_t&gt;     enqueue_pos_;
  cacheline_pad_t         pad2_;
  std::atomic&lt;size_t&gt;     dequeue_pos_;
  cacheline_pad_t         pad3_;
  </code></pre></li>
  </ol>
  
  <p>Would this concept work under gcc for c code?</p>