How is an array stored in memory and brought to cache?

Here I draw some diagrams to show how arrays look like in memory and in cache. This is not a programming problem, but let's assume we use C not Java.

The following diagram shows how a 8*8 array/matrix stored in memory by using row-major. If CPU need A[0][7] element, the whole block that contains this element will be brought to cache. In this case, the cache block can fit 8 elements, so it is the whole row that will be brought to cache.

This diagram shows how CPU request a byte from memory hierarchy. It shows how the requested element looks like in memory and how it is brought to cache.

This diagram shows why cache views memory as an array of blocks. The block size is determined by cache block and there are totally #(total memory size/cache block size) memory blocks.

Category >> CS Courses  
If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
String foo = "bar";

  1. Bhavesh Parmar on 2013-9-3

    Very nicely explained..thank you.

Leave a comment