Write a C or C++ program to simulate the following contiguous memory allocation techniques a) Worst-fit...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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
Expert Answer:
Answer rating: 100% (QA)
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 the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
There is an XYZ Company, which purchases some parts from vendors to produce some products. It has several departments, marketing sites, and parts supply vendors in the company. 1) For each...
-
It happens all too often. As a market researcher, you slave away for countless hours in pursuit of insightful data but, to your shock, your research report flops and your data are dead in the water....
-
A gasoline engine has a power output of 180 kW (about 241 hp). Its thermal efficiency is 28.0%. (a) How much heat must be supplied to the engine per second? (b) How much heat is discarded by the...
-
Explain where these activities appear in Canadas National Income and Expenditure Accounts. The components and robots for Toyotas auto assembly lines in Canada are built in Japan. Toyota assembles...
-
William Stem filed an action against Gary Braden, seeking to rescind a contract for the sale of an automobile and to obtain the return of the purchase price plus interest. The trial court granted...
-
In recent years, Farr Company has purchased three machines. Because of frequent employee turnover in the accounting department, a different accountant was in charge of selecting the depreciation...
-
Problem 3 For a multiple linear regression model with 4 variables, where ~ Y = Bo+B1X1 + B2X2 + 3X3 + B4X4 + , N(0,2), what is the test statistic for each of the following tests? and what is the...
-
REI sells snowboards. Assume the following information relates to REI's purchases of snowboards during September. During the same month, 102 snowboards were sold. REI uses a periodic inventory...
-
What is the experience about? An adventure into the nature reserve with dinosaur tales on as the children venture through nature and learn about dinosaurs and what it would be like to be a dinosaur...
-
How does ethnic identity intersect with broader social constructs such as race and nationality in contemporary societies?
-
What are some of the benefits of juvenile courts? Are there any arguments to be made against them?
-
What is "invisible blackness"? Why was it of such concern to those who supported racial classification laws?
-
How did the U.S. Constitution and laws affect the development of the U.S. courts?
-
How does the concept of "ethnicity" differ across various academic disciplines such as anthropology, sociology, and political science, and what implications does this interdisciplinary variation have...
-
Berkshire Hathaway Inc. has almost a "personality cult" organizational culture which essentially revolves around one man and his investing prowess. The man's name is Warren Buffett, the "Oracle of...
-
Evenflow Power Co. is considering a new project that is a little riskier than the current operations of the company. Thus, management has decided to add an additional 1.5% to the company's overall...
-
Find and correct the error(s) in each of the following segments of code: a) For (i = 100, i >= 1, ++i) { Console.WriteLine(i); } b) The following code should display whether integer value is odd or...
-
Implement the bubble sortanother simple, yet inefficient, sorting technique. Its called bubble sort or sinking sort because smaller values gradually bubble their way to the top of the array (i.e.,...
-
A large company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9% of their gross sales for that week. For example, a salesperson who sells $5,000 worth of...
-
With regard to genotypes, what is a true-breeding organism?
-
With regard to biological evolution, which of the following statements is incorrect? Explain why. A. During its lifetime, an animal evolves to become better adapted to its environment. B. The process...
-
Marfan syndrome is a rare inherited human disorder characterized by unusually long limbs and digits plus defects in the heart (especially the aorta) and the eyes, among other symptoms. Following is a...
Study smarter with the SolutionInn App