Question: #include #include #include #include int main() { clock_t start1, end1, start2, end2; int m = 32000; int size = 3*m; int **array1 = (int**)malloc(size*(sizeof(int*))); int

 #include #include #include #include int main() { clock_t start1, end1, start2,

#include #include #include #include

int main() {

clock_t start1, end1, start2, end2;

int m = 32000;

int size = 3*m;

int **array1 = (int**)malloc(size*(sizeof(int*)));

int **array2 = (int**)malloc(m*(sizeof(int*)));

printf("1st allocation for m = %i ", m);

start1 = clock();

for(int i = 0; i

array1[i] = (int*)malloc(800000*sizeof(int));

}

end1 = clock();

for(int i = 0; i

free(array1[i]);

}

printf("2nd allocation for m = %i ", m);

start2 = clock();

for(int i = 0; i

array2[i] = (int*)malloc(900000*sizeof(int));

}

end2 = clock();

double time1 = (double)(end1-start1)/CLOCKS_PER_SEC;

double time2 = (double)(end2-start2)/CLOCKS_PER_SEC;

printf("1st allocation Execution time: %fs ", time1);

printf("2nd allocation Execution time: %fs ", time2);

return 0;

}

my timings get larger for the first allocation as my m gets bigger. What is the explanation for this?

4. Memory fragmentation in C: Design, implement, and execute a C-program that does the following: It allocates memory for a sequence of 3m arrays of size 800,000 elements each; then it explicitly deallocates all even-numbered arrays and allocates a sequence of m arrays of size 900,000 elements each. Measure the amounts of time your program requires for the allocation of the first sequence and for the second sequence. Choose m so that you exhaust almost all of the main memory available to your program. Explain your timings

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!