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
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 timingsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started