If a block is returned to the FREE list, it should be inserted in the correct or
ID: 3875934 • Letter: I
Question
If a block is returned to the FREE list, it should be inserted in the correct order. If it can be combined with other blocks to create a larger free block, it should be If a block is inserted into the ALLOCATED list, it should be in order. You need to create a Memory Class that will manage a block of continuous memory. You should be ab to set the size of the block when you create the Object of the class Your class should manage the free and allocated space. You should use a dynamic node implementation of link list to implement both lists for this assignment. You should be able to request memory blocks for jobs and de-allocate the memory blocks when the job is done. You should also be able to ask how much free memory is currently available, how much allocated memory is currently in th system, what is the largest block of free memory available, what is the total amount of memory being managed by the object, and how much memory a specific job has allocated. You should also be able to print a report listing all jobs in the system with how much memory each has allocated and where that memory is and a report that basically does a memory dump showing usage of all memory The methods are shown in the examples below: Create a memory manager for 256M of memory Memory meml (256); meml.allocmem (3, 56) 1/ Request 56M of memory for job 3 meml.freemem (3); coutExplanation / Answer
#include <iostream>
using namespace std;
int main ()
{
// Pointer initialization to null
int* p = NULL;
// Request memory for the variable
// using new operator
p = new int;
if (!p)
cout << "allocation of memory failed ";
else
{
// Store value at allocated address
*p = 29;
cout << "Value of p: " << *p << endl;
}
// Request block of memory
// using new operator
float *r = new float(75.25);
cout << "Value of r: " << *r << endl;
// Request block of memory of size n
int n = 5;
int *q = new int[n];
if (!p)
cout << "allocation of memory failed ";
else
{
for (int i = 0; i < n; i++)
q[i] = i+1;
cout << "Value store in block of memory: ";
for (int i = 0; i < n; i++)
cout << q[i] << " ";
}
// freed the allocated memory
delete p;
delete r;
// freed the block of allocated memory
delete[] q;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.