Question: In this lab, you will implement the memory management system described in section 3.2.3 of the textbook. Your implementation must use a list, not a
In this lab, you will implement the memory management system described in section 3.2.3 of the textbook. Your implementation must use a list, not a bitmap. You must use the C++ list class, which implements a doubly linked list, for your list.
Setup
In CodeLite on your virtual machine:
Create a C++ project names Lab4.
Create a class named Memory_Chunk. Objects of this class will be used to represent either a single process or a single hole.
Create a class named Memory_Manager.
Command Line
Your program should accept a single command-line argument, the name of the input file.
Input File Format
All fields on a line are separated by whitespace.
The first line of the input file contains a string and a single integer. The string is the algorithm and the number is the total amount of memory in the system.
Following that, the file contains one action per line. Each line consists of a command string. If the command is "load" the rest of the line contains a process name (a string with no whitespace) and the space requested by the process. Note that there may not be enough free space to fulfill this request without compaction of memory.
If the command is "unload" the rest of the line contains only a process name to remove from memory. You may assume the process already exists in memory. Here is an example file:
firstFit 50
load A 10
load B 10
load C 2
load D 1
load E 2
unload A
Assignment
You are to read in the input file and create a list to manage memory. You should have a single list that holds all the memory chunks (memory units). Each chunk should either contain the process name loaded into it or something to indicate it is a hole. Each chunk should also contain its starting address and size. When the simulation starts, the list should contain a single hole that fills the entire memory.
When you perform a load, you will find the correct hole for the new process based on the algorithm indicated in the first line of the file. You need to be able to handle the firstFit, bestFit, and worstFit algorithms. In the example output below, these 3 algorithms all produce the exact same results until the point where H is loaded. At that point they differ. Make sure you try all three algorithms in your testing.
When a process is unloaded nearby holes need to be combined to create a single large hole. That is, you should never have two holes next to each other on the hole list. This is shown in Figure 3-7 of your textbook and is also demonstrated in the results below.
Testing Hint: You may want to create smaller test files so you can test individual cases of your code, for example removing a process at the beginning of the list, the end of the list, the middle of the list and combining holes in the various situations shown in Figure 3-7.
If a process is requesting more space that any hole, then your code should indicate that and not load the process. Normally, this is when a memory compaction algorithm would be run to combine all the free space together. We will not be implementing a compaction algorithm for this lab.
Implementation Notes
Your project must use the C++ list class (http://www.cplusplus.com/reference/list/list/ to store your memory chunks. std::list is the C++ implementation of a doubly linked list. Memory_Chunk Class
The constructor should have three parameters: the name of the process or a name to indicate a hole, the starting address of the memory chunk and the size of the chunk.
You should create accessor and mutator methods as needed. Memory_Manager Class The constructor should have one parameter, the name of the input file.
The Memory_Manager Class should have one public member function named run. Your main method should: Check to see if the correct number of command line arguments is given.
Create an object of type Memory_Manager.
Call the Memory_Manager objects run method to start the simulation.
Sample Output for Example Input File
hole: start 0, size 50
load A 10
A: start 0, size 10
hole: start 10, size 40
load B 10
A: start 0, size 10
B: start 10, size 10
hole: start 20, size 30
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
