1
$\begingroup$

Starting with two examples:

  1. for(i = 1; i<10; i++) {B[i] = 0;}

  2. for(i = 1; i<10; i++) {B[2i] = 0;}

In the first example, the successive accesses to the array are in contiguous locations whereas in the second example they are at alternating locations. Therefore, the total access time is lesser in the first case.

Now, if we have two arrays in one loop like: for (i=0; i<10;i++) {A[i] = 0; B[2i] = 0;}

It would be efficient to interleave the elements of both the arrays to reduce the total access time. We can also split it into two different loops, I don't understand how.

However, what do I do in case of more than one loop and more than one arrays? The primary thing that comes to my mind is always interleaving them. Another problem posed is that we can't interleave like this in memory so what am I supposed to do?

tl;dr

  1. How exactly do I reduce the total access time for more than one loops and arrays? An example would really help me.

  2. Even if I find out how to do so, how do I store them in the memory?

New contributor
Ice Inkberry is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$

Your Answer

Ice Inkberry is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.