Programmers who understand the nature of the memory hierarchy can exploit this understanding to write
more efficient programs, regardless of the specific memory system organization. In particular, we recommend
the following techniques:
1. Focus your attention on the inner loops where the bulk of the computations and memory accesses
occur. 集中在最内层的循环。
2.Try to maximize the spatial locality in your programs by reading data objects sequentially, in the order
they are stored in memory.提高空间locality,顺序读取数据。
根据 memory moutain(section 6.6.1)和 section 6.6.3的结论,这个inner loop顺序读取内存的大小最好小于L1 cache的大小。
3. Try to maximize the temporal locality in your programs by using a data object as often as possible
once it has been read from memory.
4. Remember that miss rates are only one (albeit important) factor that determines the performance
of your code. The number of memory accesses also plays an important role, and sometimes it is
necessary to trade off between the two. 记住,cache的miss rate只是一个影响性能的因素,内存访问次数也很关键。
这个结论来自与section 6.6.2.