title: C++ Memory alignment - should we care?
body: <p>Consider working on an x64 bit Windows operation system with the following type alignments:</p>
  
  <p><a href="https://i.stack.imgur.com/BqRXQ.png" rel="noreferrer"><img src="https://i.stack.imgur.com/BqRXQ.png" alt="C++ build in types alignments on my pc"></a></p>
  
  <p>As far as I understand, it is very bad to do something like this:</p>
  
  <pre><code>struct X_chaotic
  {
      bool flag1;
      double d1;
      bool flag2;
      double d2;
      bool flag3;
      double d3;
      //... and so on ...
  };
  </code></pre>
  
  <p>According to <a href="https://www.youtube.com/watch?v=gonq59MxxcM" rel="noreferrer">C++ Alignment, Cache Line and Best Practice</a>
  and <a href="https://en.wikipedia.org/wiki/Data_structure_alignment" rel="noreferrer">Data structure alignment</a>, 
  it should be better/faster and much more compact to write this:</p>
  
  <pre><code>struct X_alignOrder
  {
      double d1;
      double d2;
      double d3;
      //... all other doubles ...
      bool flag1;
      bool flag2;
      bool flag3;
      //... all other bools ...
  };
  </code></pre>
  
  <p>The members are declared in the order of the alignment size, starting with the highest alignment.</p>
  
  <p>Is it safe to say it is a good idea to order the declaration of the data members by alignment size? Would you say it is best practice? Or does it make no difference?</p>
  
  <p>(I heard that the compiler can not rearrange the defined order, due to the C++ standard, and this even holds for all data members declared in access specifier blocks of a class)</p>
  
  <p>Because I never read about this, neither in Scott Meyers' books nor in Bjarne Stroustrup's books, I wonder if I should start reordering the data declarations by alignment for my day-to-day work.</p>