Cpu 对于可能被多次访的内存区域,会将其复制到 cache 中,之后访问不再从主存中获取,提升效率。从 ram 到 cache 的复制过程(Block Transfer),复制单位为 linesize ,此处为 64 byte。
请看如下代码段,1 与 2 所需时间差不多,甚至 2 有时时间比 1 还长 。
1 | // int : 4 byte |
1 与 2 Block transfer 次数相同,时间不会差太多
3 相比于 1 和 2 Block transfer 少了一倍,时间与其相差略小于一倍