Array

advantage of using array

  1. Arrays have better cache locality that can make a pretty big difference in performance
  2. Arrays allow random access of elements. This makes accessing elements by position faster

第一个优点的意思,数组有更高的缓存位置(cache locality,这样子翻译好别扭),会产生很大的差异,在性能上。cache locality链接:https://en.wikipedia.org/wiki/Locality_of_reference,大概意思就是 数组 具有顺序局部性,和程序局部性原理意思差不多,在访问某个内存地址中的内容时,可能会接着访问其下一个地址空间的内容。

原文地址:https://www.cnblogs.com/AI-Cobe/p/9310750.html