the code.txt is the code so far done and reports.pdf is the (assignment) work that needs to be finished in the code.txt and now I have test.txt which you can use to test the two functions, just need...

1 answer below »
the code.txt is the code so far done and reports.pdf is the (assignment) work that needs to be finished in the code.txt and now I have test.txt which you can use to test the two functions, just need the two Functions, Report_Jobs and Report_Memory done by Wednesday, the functions can't have any advanced code in them, like one of them I think should be an array but the limit is 100 and you use a while loop I think to print it out. It should be kind of basic code, no like tables or anything, unless like an array or something


Here is the format to use for the following two services of the memory manager. 1. Report_Jobs For each job you should report each block of memory they use. You should report the blocks in order but you do NOT have to report the jobs in order of job number. The Colum Headers should also be printed (the green below) JOB Memory Usage 1 10 – 50 54 – 75 200 – 240 5 1 – 9 101 – 134 3 180 – 184 185 – 192 2. Report_Memory This should be a sequential dump of all memory showing usage. Memory Block JOB 0 – 9 5 10 – 50 1 51 – 53 FREE 54 – 75 1 76 – 100 FREE 101 – 134 5 135 – 179 FREE 180 – 184 3 185 - 192 3 193 – 199 FREE 200 – 240 1 241 – 255 FREE #include #include // for setw() using namespace std; /******************************************* ******************************************** */ // GLOBAL DATA STRUCTURES ======================= typedef struct FREE_NODE * FREEPTR; typedef struct ALLOCNODE * ALLOCPTR; struct FREE_NODE // FREE LIST NODES { int start_byte; int end_byte; int size; FREEPTR next; }; struct ALLOCNODE // ALLOCTADED LIST NODES { int start_byte; int end_byte; int size; int id; ALLOCPTR next; }; // ====== GLOBAL DATA ========================= FREEPTR freelist = NULL; // the FREE link list ALLOCPTR alloclist = NULL; // the ALLOCATED link list int total_memory_managed = 0; // the amount of memory managed //====== PROTOTYPES =========================== //--- test only --- void dump_freelist(void); void dump_alloclist(void); //--- utility --- void remove_empty_freenodes(void); void insert_freeblock(FREEPTR fptr); void merge_freenodes(void); //--- interface --- void init_memory_manager(const int amount); int allocate_memory(const int job, const int amount); void release_memory(const int job); int total_free(void); int total_allocated(void); int largest_free(void); int job_allocated(const int job); void report_memory(void); //STUB void report_jobs(void); // STUB //========== MAIN ============================= int main(void) { char ch ; // used to pause between tests int r; // results of allocate_memory // ================================================================================ cout < "="==================================="">< endl;="" cout="">< "="" author="" :=""> " < endl;="" cout="">< "="==================================="">< endl;="" cout="">< endl;="" cout="">< "enter="" a="" character="" ";="" cin="">>ch; cout < endl;="" =="===============================================================================" cout="">< "="==================================="">< endl;="" cout="">< "test="" #="" 1"="">< endl;="" cout="">< "="==================================="">< endl="">< endl;="" init_memory_manager(200);="" r="allocate_memory(1,200);" cout="">< "allocate_memory="" returns="" :="" "="">< r="">< endl="">< endl;="" all="" memory="" r="allocate_memory(2,30);" cout="">< "allocate_memory="" returns="" :="" "="">< r="">< endl="">< endl;="" over="" allocate="" release_memory(1);="" free="" all="" memory="" r="allocate_memory(1,-1);" cout="">< "allocate_memory="" returns="" :="" "="">< r="">< endl="">< endl;="" try="" allocate="" -1="" r="allocate_memory(3,0);" cout="">< "allocate_memory="" returns="" :="" "="">< r="">< endl="">< endl;="" allocate="" 0="" r="allocate_memory(1,256);" cout="">< "allocate_memory="" returns="" :="" "="">< r="">< endl="">< endl;="" over="" allocate="" r="allocate_memory(1,100);" cout="">< "allocate_memory="" returns="" :="" "="">< r="">< endl="">< endl;="" ok="" allocate="" 100="" cout="">< "total="" free="" memory="" is="" :="" "="">< total_free()="">< endl;="" 100="" cout="">< "total="" alloc="" memory="" is="" :="" "="">< total_allocated()="">< endl;="" 100="" release_memory(1);="" free="" up="" memory="" cout="">< endl;="" cout="">< "enter="" a="" character="" ";="" cin="">>ch; cout < endl;="" *="" =="===============================================================================" cout="">< "="==================================="">< endl;="" cout="">< "test="" #="" 2="" [deallocate="" several="" of="" same="" ]="" "="">< endl;="" cout="">< "="==================================="">< endl="">< endl;="" init_memory_manager(200);="" r="allocate_memory(1,20);" cout="">< "allocate_memory="" returns="" :="" "="">< r="">< endl="">< endl;="" r="allocate_memory(2,30);" cout="">< "allocate_memory="" returns="" :="" "="">< r="">< endl="">< endl;="" r="allocate_memory(1,20);" cout="">< "allocate_memory="" returns="" :="" "="">< r="">< endl="">< endl;="" r="allocate_memory(3,30);" cout="">< "allocate_memory="" returns="" :="" "="">< r="">< endl="">< endl;="" r="allocate_memory(1,20);" cout="">< "allocate_memory="" returns="" :="" "="">< r="">< endl="">< endl;="" cout="">< "total="" free="" memory="" is="" :="" "="">< total_free()="">< endl;="" cout="">< "total="" alloc="" memory="" is="" :="" "="">< total_allocated()="">< endl;="" release_memory(1);="" =="====================" report_memory();="" report_jobs();="" for="" testing="" until="" reports="" done="" ***="" remove="" from="" final="" ***="" dump_freelist();="" dump_alloclist();="" =="================================================" cout="">< "total="" free="" memory="" is="" :="" "="">< total_free()="">< endl;="" 100="" cout="">< "total="" alloc="" memory="" is="" :="" "="">< total_allocated()="">< endl;="" 100="" cout="">< endl;="" cout="">< "enter="" a="" character="" ";="" cin="">>ch; cout < endl;="" *="" =="===============================================================================" cout="">< "="==================================="">< endl;="" cout="">< "test="" #="" 3="" between="" [merge="" to="" both="" blocks]"="">< endl;="" cout="">< "="==================================="">< endl="">< endl;="" init_memory_manager(200);="" r="allocate_memory(1,25);" cout="">< "allocate_memory="" returns="" :="" "="">< r="">< endl="">< endl;="" r="allocate_memory(2,25);" cout="">< "allocate_memory="" returns="" :="" "="">< r="">< endl="">< endl;="" r="allocate_memory(3,25);" cout="">< "allocate_memory="" returns="" :="" "="">< r="">< endl="">< endl;="" r="allocate_memory(4,25);" cout="">< "allocate_memory="" returns="" :="" "="">< r="">< endl="">< endl;="" r="allocate_memory(5,25);" cout="">< "allocate_memory="" returns="" :="" "="">< r="">< endl="">< endl;="" =="===================" cout="">< "="======================="">< endl="">< endl;="" cout="">< "total="" free="" memory="" is="" :="" "="">< total_free()="">< endl;="" 100="" cout="">< "total="" alloc="" memory="" is="" :="" "="">< total_allocated()="">< endl;="" 100="" release_memory(1);="" release_memory(3);="" release_memory(2);="" =="====================" report_memory();="" report_jobs();="" for="" testing="" until="" reports="" done="" ***="" remove="" from="" final="" ***="" dump_freelist();="" dump_alloclist();="" cout="">< endl;="" cout="">< "enter="" a="" character="" ";="" cin="">>ch; cout < endl;="" =="================================================" =="===============================================================================" cout="">< "\n\n="==================================="">< endl;="" cout="">< "test="" #="" 4="" [deallocate="" several="" of="" same="" make="" merge="" ]="" "="">< endl;="" cout="">< "="==================================="">< endl="">< endl;="" init_memory_manager(200);="" r="allocate_memory(1,20);" cout="">< "allocate_memory="" returns="" :="" "="">< r="">< endl="">< endl;="" r="allocate_memory(3,20);" cout="">< "allocate_memory="" returns="" :="" "="">< r="">< endl="">< endl;="" r="allocate_memory(1,30);" cout="">< "allocate_memory="" returns="" :="" "="">< r="">< endl="">< endl;="" (a)="" r="allocate_memory(4,20);" cout="">< "allocate_memory="" returns="" :="" "="">< r="">< endl="">< endl;="" r="allocate_memory(1,20);" cout="">< "allocate_memory="" returns="" :="" "="">< r="">< endl="">< endl;="" r="allocate_memory(1,20);" cout="">< "allocate_memory="" returns="" :="" "="">< r="">< endl="">< endl;="" (b)="" cout="">< "total="" free="" memory="" is="" :="" "="">< total_free()="">< endl;="" cout="">< "total="" alloc="" memory="" is="" :="" "="">< total_allocated()="">< endl;="" release_memory(1);="" (c)="" =="================================================" cout="">< "\ntotal="" free="" memory="" is="" :="" "="">< total_free()="">< endl;="" 100="" cout="">< "total="" alloc="" memory="" is="" :="" "="">< total_allocated()="">< endl;="" 100="" cout="">< endl;="" cout="">< "enter="" a="" character="" ";="" cin="">>ch; cout < endl;="" */="" return="" 0;="" }="" =="============================================" =="=====" interface="" functions="=================" =="============================================" *="=============================================" void="" init_memory_manager="" (const="" int="" amount)="" description:="" set="" the="" initial="" data="" structures="" for="" the="" memory="" manager.="" parameters:="" amount="" :="" the="" number="" of="" bytes="" to="" be="" managed="" return="" value:="" none="" notes:="" should="" set="" up="" lists="" and="" set="" the="" total_memory_managed="" variable="===============================================*/" void="" init_memory_manager="" (const="" int="" amount)="" {="" total_memory_managed="amount;" set="" up="" the="" allocation="" list="" alloclist="NULL;" set="" up="" the="" free="" list="" with="" starting="" node="" freelist="new" free_node;="" freelist="" -=""> start_byte = 0; freelist -> end_byte = amount - 1; freelist -> size = amount; freelist -> next = NULL; return ; } /* ======================================== int total_free(void); Description: compute the total number of bytes not allocated Parameters: NONE Return value: the amount of total free bytes Notes: ===========================================*/ int total_free(void) { int amount = 0; FREEPTR tmp = freelist; while (tmp != NULL) { amount = amount + tmp->size; tmp = tmp->next; } return amount; // return amount of free memory } /* ======================================== int total_allocated(void); Description: compute the total number of bytes allocated Parameters: NONE Return value: the amount of total allocated bytes Notes: ===========================================*/ int total_allocated(void) { int amount = 0; ALLOCPTR tmp = alloclist; while (tmp != NULL) { amount = amount + tmp->size; tmp = tmp->next; } return amount; // return amount of allocated memory }; /* ======================================== int largest_free(void); Description: find the largest available free block of memory Parameters: NONE Return value: the amount of free memory in the block Notes: ===========================================*/ int largest_free(void) { int amount = 0; FREEPTR tmp = freelist; while (tmp != NULL) { if (tmp->size > amount) amount = tmp->size; tmp = tmp->next; } return amount; } /* ======================================== int job_allocated(const int job); Description: compute the total amount of memory allocated to a particular job. Parameters: -job : the
Answered Same DaySep 24, 2020Swinburne University of Technology

Answer To: the code.txt is the code so far done and reports.pdf is the (assignment) work that needs to be...

Meenakshi answered on Sep 26 2020
134 Votes
#include
#include // for setw()
using namespace std;
/*******************************************
********************************************
*/
// GLOBAL DATA STRUCTURES =======================
typedef struct FREE_NODE * FREEPTR;
typedef struct ALLOCNODE * ALLOCPTR;
struct FREE_NODE // FREE LIST NODES
{
int start_byte;
int end_byte;
int size;

FREEPTR next;
};
struct ALLOCNODE // ALLOCTADED LIST NODES
{
int start_byte;
int end_byte;
int size;
int id;

ALLOCPTR next;
};
// ====== GLOBAL DATA ====================
=====
FREEPTR freelist = NULL; // the FREE link list
ALLOCPTR alloclist = NULL; // the ALLOCATED link list
int total_memory_managed = 0; // the amount of memory managed
//====== PROTOTYPES ===========================
//--- test only ---
void dump_freelist(void);
void dump_alloclist(void);
//--- utility ---
void remove_empty_freenodes(void);
void insert_freeblock(FREEPTR fptr);
void merge_freenodes(void);
//--- interface ---
void init_memory_manager(const int amount);
int allocate_memory(const int job, const int amount);
void release_memory(const int job);
int total_free(void);
int total_allocated(void);
int largest_free(void);
int job_allocated(const int job);
void report_memory(void); //STUB
void report_jobs(void); // STUB
//========== MAIN =============================
int main(void)
{
char ch ; // used to pause between tests
int r; // results of allocate_memory
// ================================================================================
cout << "====================================" << endl;
cout << " AUTHOR : " << endl;
cout << "====================================" << endl;
cout << endl;
cout << "ENTER A CHARACTER ";
cin >>ch;
cout << endl;
//=================================================================================
cout << "====================================" << endl;
cout << "TEST # 1" << endl;
cout << "====================================" << endl << endl;
init_memory_manager(200);

r = allocate_memory(1,200);
cout << "allocate_memory returns : " << r << endl << endl; // ALL memory
r = allocate_memory(2,30);
cout << "allocate_memory returns : " << r << endl << endl; // over allocate

release_memory(1); // free all memory

r = allocate_memory(1,-1);
cout << "allocate_memory returns : " << r << endl << endl; // try allocate -1
r = allocate_memory(3,0);
cout << "allocate_memory returns : " << r << endl << endl; // allocate 0
r = allocate_memory(1,256);
cout << "allocate_memory returns : " << r << endl << endl; // over allocate
r = allocate_memory(1,100);
cout << "allocate_memory returns : " << r << endl << endl; //Ok allocate 100

cout << "total free memory is : " << total_free() << endl; // 100
cout << "total alloc memory is : " << total_allocated() << endl; // 100

release_memory(1); //free up memory

cout << endl;
cout << "ENTER A CHARACTER ";
cin >>ch;
cout << endl;
/*
// =================================================================================
cout << "====================================" << endl;
cout << "TEST # 2 [Deallocate several of same ] " << endl;
cout << "====================================" << endl << endl;
init_memory_manager(200);
r = allocate_memory(1,20);
cout << "allocate_memory returns : " << r << endl << endl;
r = allocate_memory(2,30);
cout << "allocate_memory returns : " << r << endl << endl;
r = allocate_memory(1,20);
cout << "allocate_memory returns : " << r << endl << endl;
r = allocate_memory(3,30);
cout << "allocate_memory returns : " << r << endl << endl;
r = allocate_memory(1,20);
cout << "allocate_memory returns : " << r << endl << endl;

cout << "total free memory is : " << total_free() << endl;
cout << "total alloc memory is : " << total_allocated() << endl;

release_memory(1);
//======================
//report_memory();
//report_jobs();

//for testing until reports done *** remove from final ***
dump_freelist();
dump_alloclist();
//==================================================

cout << "total free memory is : " << total_free() << endl; // 100
cout << "total alloc memory is : " << total_allocated() << endl; // 100

cout << endl;
cout << "ENTER A CHARACTER ";
cin >>ch;
cout << endl;
/*
// =================================================================================
cout << "====================================" << endl;
cout << "TEST # 3 BETWEEN [merge to both blocks]" << endl;
cout << "====================================" << endl << endl;
init_memory_manager(200);
r = allocate_memory(1,25);
cout << "allocate_memory returns : " << r << endl << endl;
r = allocate_memory(2,25);
cout << "allocate_memory returns : " << r << endl << endl;
r = allocate_memory(3,25);
cout << "allocate_memory returns : " << r << endl << endl;
r = allocate_memory(4,25);
cout << "allocate_memory returns : " << r << endl << endl;
r = allocate_memory(5,25);
cout << "allocate_memory returns : " << r << endl << endl;
//=====================
cout << "========================" << endl << endl;
cout << "total free memory is : " << total_free() << endl; // 100
cout << "total alloc memory is : " << total_allocated() << endl; // 100
release_memory(1);
release_memory(3);
release_memory(2);
//======================
//report_memory();
//report_jobs();

//for testing until reports done *** remove from final ***
//dump_freelist();
//dump_alloclist();

cout << endl;
cout << "ENTER A CHARACTER ";
cin >>ch;
cout << endl;
//==================================================
//...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here