title: Is data allocated on the heap slower to access than data allocated on the stack?
body: <p>I've heard conflicting opinions on that matter.</p>
  
  <p>Some say that accessing data allocated on the heap (ie <code>std::vector</code> or dynamic arrays allocated through <code>malloc</code>) is always marginally slower than accessing data allocated on the stack, because the process must always go through an intermediate pointer to access that data, which is likely located on a wholly different area of memory; on the other hand, they maintain, accesing data allocated on the stack doesn't require going through this intermediate pointer and this data is likely already cached.</p>
  
  <p>Others claim that only allocation of data is slower on the heap than on the stack (because of the overhead of <code>malloc</code>, <code>mmap</code> and similar functions), but access is not, except for the rare cases when the stack and the heap are located on different physical drives.</p>
  
  <p>What is the truth?</p>