title: will storing pointers in array benefit from CPU cache speed up?
body: <p>As far as I know, in theory if I store data in continuous memory, for example an array, when the first element of the array is read by cpu, because of striding, cpu can load the entire array to its L1 cache(if the array can fit in L1 cache), therefore reducing cache miss when reading the other array elements.</p>
  
  <p>But what if the array stores pointers, and cpu has to dereference the pointer and perform some operations on it, which will lead to other part of memory being loaded to L1 cahce. 
  For example if my L1 data cache is 32KB, and I have an array of 8K elements:</p>
  
  <pre><code>MyObject* myarray[8192];
  //...
  for (int i=0; i &lt; 8192; ++i) {
      MyObject&amp; obj = *myarray[i];
      obj.doSomethingComplicated();
  }
  </code></pre>
  
  <p>In this case the total size of myarray will be 4x8 = 32KB, am I right at least part of the L1 cache will likely to be trashed when doSomethingComplicated() is performed? And therefore trying to limit myarray size so that it can fit in a L1 cache is pointless?</p>
  
  <p>In reality, I can still see a small but repeatedly measurable performance increase when choosing a relatively small size for myarray, but I can't really explain why.</p>
  
  <p>I'm only concerned about x86_64 as I'm totally unfamiliar with other platforms.</p>