Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- /* Objective: Exhaust the memory to understand fragmentation and explain the timings.
- *
- */
- int main(int argc, char** argv)
- {
- double t, t2;
- double dif, dif2;
- const int m = 100; //Change this
- printf("Step One\n"); //DO NOT CHANGE
- int **container= new int*[3 * m];
- //int **container2=new int*[m];
- t = clock();
- for(int i = 0; i < (3 * m); i++)
- {
- container[i]=new int[800000];
- }
- t = clock()-t;
- t2=clock();
- printf("Step Two\n"); //DO NOT CHANGE
- for(int i = 0; i < (3 * m); i += 2)
- {
- delete[] container[i];
- //container[i]=NULL;
- }
- printf("Step Three\n\n"); //DO NOT CHANGE
- for(int i = 0; i <(3*m); i +=2)
- {
- container[i]=new int[900000];
- }
- t2=clock()-t2;
- printf("First array allocation: %.5f\n", t*1000000);
- printf("Second array allocation: %.5f\n", t2*1000000);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement