Question: One critical task every operating system must perform is that of memory management. This include assigning available positions in memory to program requests and trying
One critical task every operating system must perform is that of memory management. This include assigning available positions in memory to program requests and trying to do so as efficiently as possible. While we will discuss memory allocation strategies in more depth later, one of the easiest to use is called first-fit, in which space is assigned to a program in the first available contiguous position in memory. For this part of the lab, you will need to write a program in C++ in which you simulate an operating system allocating memory to a series of 6 programs, numbered 1 through 6. The operating system starts out with a contiguous block of 20 bytes of memory, and each program will require a random amount of contiguous memory between 1 and 3 bytes. Your system should allocate memory to each program in the lowest position memory cell and then output the entire state of memory after each completed allocation. Therefore, you program should: Define an array of 20 integers, such that each position in the array represents a single byte of memory Define an integer pointer that points to the beginning of the array Seed your random number generator using the current time in milliseconds Initialize all positions in the array to 0 For each program o Generate a random required amount of memory between 1 and 3 bytes, inclusively o Starting at the first available byte in memory, denoted by your pointer, assign the id of the process to each slot in the array so that the program is assigned a number of slots equal to the required number of bytes Note you should not be searching for the first available slot each time, only using your pointer to keep track of the first available slot o Update the pointer to the new closest available byte of memory o Output the number of bytes required by the program with an appropriate message o Output the state of all slots in the array
Your output should look similar to the following: Program 1 required 1 bytes of memory. 10000000000000000000 Program 2 required 2 bytes of memory. 12200000000000000000 Program 3 required 3 bytes of memory. 12233300000000000000 Program 4 required 1 bytes of memory. 12233340000000000000 Program 5 required 1 bytes of memory. 12233345000000000000 Program 6 required 3 bytes of memory. 12233345666000000000
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
