<p>If your class looks like this:</p>
<pre class="lang-cpp prettyprint-override"><code>struct Person {
  double age;
  double income;
  size_t location;
};
</code></pre>
<p>then you <em>might</em> benefit from rearranging to</p>
<pre class="lang-cpp prettyprint-override"><code>std::vector&lt;double&gt; ages;
std::vector&lt;double&gt; incomes;
std::vector&lt;size_t&gt; locations;
</code></pre>
<p>But it depends on your access patterns. If you frequently access multiple elements of a person at a time, then having the elements blocked together makes sense.</p>
<p>If your class looks like this:</p>
<pre class="lang-cpp prettyprint-override"><code>struct Population {
  std::vector&lt;double&gt; many_ages;
  std::vector&lt;double&gt; many_incomes;
  std::vector&lt;size_t&gt; many_locations;
};
</code></pre>
<p>Then you're using the form your resource recommended. Using any one of these arrays individually is faster than using the first class, but using elements from all three arrays simultaneously is probably slower with the second class.</p>
<p>Ultimately, you should structure your code to be as clean and intuitive as a possible. The biggest source of speed will be a strong understanding and appropriate use of algorithms, not the memory layout. I recommend disregarding this unless you already have strong HPC skills and need to squeeze maximum performance from your machine. In almost every other case your development time and sanity is worth far more than saving a few clock cycles.</p>
<p><strong>More broadly</strong></p>
<ol>
<li><p>An interesting paper related to this is <a href="https://arxiv.org/abs/1903.03129" rel="nofollow noreferrer">SLIDE: In Defense of Smart Algorithms over Hardware Acceleration for Large-Scale Deep Learning Systems</a>. A lot of work has gone into mapping ML algorithms to GPUs and, for ML applications, getting the memory layout right does make a real difference since so much time is spent on training and GPUs are optimized specifically for contiguous-array processing. But, the authors of the paper contend that even here if you understand algorithms well you can beat specialized hardware with optimized memory layouts, and they demonstrate this by getting their CPU to train 3.5x faster than their GPU.</p>
</li>
<li><p>More broadly, your question deals with the idea of <a href="https://en.wikipedia.org/wiki/CPU_cache#Cache_miss" rel="nofollow noreferrer">cache misses</a>. Since a cache miss is 200x more expensive than an L1 reference (<a href="https://gist.github.com/jboner/2841832" rel="nofollow noreferrer">link</a>), if your data layout is optimized to your computation, then you can really save time. <strong>However</strong>, as the above suggests, it is rarely the case that simply rearranging your data magically makes everything faster. Consider matrix multiplication. It's the perfect example because the data is laid out in a single array, as requested by your resource. However, for a simple triple-loop matmult GEMM implementation there are still 6 ways to arrange your loops. Some of these ways are much more efficient than others, but none of them give you anywhere near peak performance. Read through <a href="https://github.com/r-barnes/how-to-optimize-gemm" rel="nofollow noreferrer">this step-by-step explanation of matmult</a> to get a better sense of all the algorithmic optimizations necessary to get good performance.</p>
</li>
</ol>
<p>What the above should demonstrate is that even for situations in which we have only a few arrays laid out exactly as your resource suggests, the layout alone doesn't give us the speed. Good algorithms do. Data layout considerations, if any, flow from the algorithms we choose and higher-level hardware constraints.</p>
<p>If this is so for simple arrays and operations like matrix multiplication, by extension you should also expect it to be so for &quot;fancy data structures&quot; as well.</p>
C++ Classes for High Performance Computing
<p>According to <a href="https://www.quora.com/How-do-I-learn-C-tricks-for-high-performance-computing" rel="nofollow noreferrer">this Quora forum</a>,</p>
<blockquote>
<p>One of the simplest rules of thumb is to remember that hardware loves arrays, and is highly optimized for iteration over arrays. A simple optimization for many problems is just to stop using fancy data structures and just use plain arrays (or std::vectors in C++). This can take some getting used to.</p>
</blockquote>
<p>Are C++ classes one of those &quot;fancy data structures,&quot; i.e. a kind of data type that can be replaced by arrays to achieve a higher performance in a C++ program?</p>