在学习csapp, 看完了第六章。标记一下, 所以直接引用csapp书中内容了:
Putting It Together: Exploiting Locality in Your Programs (The Impact of Caches on Program Performance)
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:
Focus your attention on the inner loops where the bulk of the computations and memory accesses
occur.
Try to maximize the spatial locality in your programs by reading data objects sequentially, in the order
they are stored in memory.
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.
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.