Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem: I am to code using a C-program. I am doing a memory fragmentation in C++: Design, implement, and execute a C-program that does the

Problem: I am to code using a C-program. I am doing a memory fragmentation in C++: Design, implement, and execute a C-program that does the following: 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 1,000,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 we exhaust almost all of the main memory available to your program. Explain you timings!

Please edit by adding/deleting or making any correction to my code so that it may successfully debug :)

Code:

#include "header.h" void allocate_800k(int** &, int); void free_memory(int** &, int); void allocate_900k(int** &, int);

int main() { clock_t start1, end1, start2, end2; int m = 3500; int size = 3 * m; int** array_num1 = (int**)malloc(size); int** array_num2 = (int**)malloc(m); start1 = clock(); allocate_800k(array_num1, size); end1 = clock(); free_memory(array_num1, size); start2 = clock(); allocate_900k(array_num2, m); end2 = clock(); double time1 = double(end1 - start1) / CLOCKS_PER_SEC; double time2 = double(end2 - start2) / CLOCKS_PER_SEC; cout << "First allocation time: " << time1 << " ms" << endl; cout << "Second allocation time: " << time2 << " ms" << endl;

system("pause"); } void allocate_800k(int**& array_num1, int size) { for (int i = 0; i < size; i++) { array_num1[i] = (int*)malloc(800000); } } void free_memory(int**& array_num1, int size) { for (int i = 0; i < size; i += 2) { free(array_num[i]); } } void allocate_900k(int**& array_num2, int size) { for (int i = 0; i < size; i++) { array_num2[i] = (int*)malloc(900000); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems Second East European Symposium Adbis 98 Poznan Poland September 1998 Proceedings Lncs 1475

Authors: Witold Litwin ,Tadeusz Morzy ,Gottfried Vossen

1st Edition

3540649247, 978-3540649243

More Books

Students also viewed these Databases questions

Question

Is it easier to adjust goals upward or downward? Explain.

Answered: 1 week ago

Question

4. Are there any disadvantages?

Answered: 1 week ago

Question

3. What are the main benefits of using more information technology?

Answered: 1 week ago

Question

start to review and develop your employability skills

Answered: 1 week ago