Question: Write a C or C++ program to simulate the following contiguous memory allocation techniques a) Worst-fit b) Best-fit c) First-fit. For each technique submit

Write a C or C++ program to simulate the following contiguous memory allocation techniques a) Worst-fit b)

Write a C or C++ program to simulate the following contiguous memory allocation techniques a) Worst-fit b) Best-fit c) First-fit. For each technique submit the code and a screenshot of the output given the input below. All techniques can be implemented in one programm. DESCRIPTION One of the simplest methods for memory allocation is to divide memory into several fixed-sized partitions. Each partition may contain exactly one process. In this multiple-partition method, when a partition is free, a process is selected from the input queue and is loaded into the free partition. When the process terminates, the partition becomes available for another process. The operating system keeps a table indicating which parts of memory are available and which are occupied. Finally, when a process arrives and needs memory, a memory section large enough for this process is provided. When it is time to load or swap a process into main memory, and if there is more than one free block of memory of sufficient size, then the operating system must decide which free block to allocate. Best- fit strategy chooses the block that is closest in size to the request. First-fit chooses the first available block that is large enough. Worst-fit chooses the largest available block. INPUT Enter the number of blocks: 3 Enter the number of processes: 2 Enter the size of the blocks: Block 1:5 Block 2: 2 Block 3: 7 Enter the size of the processes: File 1: 1 File 2:4 OUTPUT FIRST-FIT Process No 1 2 OUTPUT BEST-FIT Process No 1 2 OUTPUT WORST-FIT Process No 1 IN 2 Process Size 1 4 Process Size 1 4 Process Size 1 4 Block No 3 Block No 2 P Block No 3 1. 1 Block Size 5 7 Block Size 2 5 Block Size 7 5 Fragment 4 3 Fragment 1 Fragment 6 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

C include using namespace std Structure to represent a memory block struct Block int size bool allocated Function to implement firstfit memory allocation void firstFitBlock blocks int nBlocks int proc... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!