edited by
195 views
0 votes
0 votes

Which of the following runs fastest (assume page size is 4096 bytes)?


a) int i, j, npages = 10000;
char *arr;
arr = (char*)malloc(4096*(npages+1));
for (i=0 ; i < npages ; i++) {
for (j=0 ; j < 4096 ; j++) {
arr[i+j] += 1;
}
}


b) int i, j, npages = 10000;
char *arr;
arr = (char*)malloc(4096*(npages+1));
for (i=0 ; i < npages*4096 ; i++) arr[i] += 1;


c) int i, j, npages = 10000;
char *arr;
arr = (char*)malloc(4096*(npages+1));
for (j=0 ; j < 4096 ; j++) {
for (i=0 ; i < npages ; i++) {
arr[i+j] += 1;
}
}

edited by

Please log in or register to answer this question.

Related questions

0 votes
0 votes
0 answers
1
Warrior asked Nov 2, 2018
505 views
Consider two processes p1 and p2 each needed 3 resources 1, 2,3 in databases. If each, processes ask them in any order, then the number of ways possible in which system i...