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.

1 thought on “How is an array stored in memory and brought to cache?”

Leave a Comment