I sum a 4096 × 4096 array of 4-byte integers in C, declared as int a[4096][4096]. With the row index in the outer loop the sum takes a fraction of the time it takes with the column index in the outer loop. Both versions perform the same 16.7 million additions.
I know the answer is supposed to be the cache, but I would like to understand the mechanism. What exactly is a cache line, and why does the order of two loops change how well it works?




