234k views
5 votes
2. Consider the two-dimensional array A: int A[][] = new int[100][100]; where A[0][0] is at location 200 in a paged memory system with pages of size 200. Asmall process that manipulates the matrix resides in page 0 (locations 0 to 199). Thus, every instruction fetch will be from page 0. For three page frames, how many page faults are generated by the following array-initialization loops? Use LRU replacement, and assume that page frame 1 contains the process and the other two are initially empty. a. for (int j = 0; j < 100; j++) for (int i = 0; i < 100; i++) A[i][j] = 0; b. for (int i = 0; i < 100; i++) for (int j = 0; j < 100; j++) A[i][j] = 0;

1 Answer

5 votes

Answer:

Check the explanation

Step-by-step explanation:

An integer (int) is of two different bytes and each page has 200 bytes in length. What this means is that each row of array A (100 int) will fits perfectly in a page.

(a) For the initial or first array-initialization loop, one column is processed at a time, so a page fault will be generated at every inner loop iteration, with a total of 100*100=10,000 page faults.

(b) And when it comes to the second array-initialization loop, one row is processed at a time, and a page fault is generated at every outer loop iteration, with a total of 100 page faults.

Hence second array-initialization loop, has better spatial locality.

User KevBot
by
5.4k points