First fit algorithm int n[5]=(4,3,8,2,3); bool full|5] = {false, false, false, false, false); II keep track of hole occupied input data block size; for(all holes) { if(found current hole size >= data size) && not occupied) { if (current hole size > data size && next hole not occupied && not last hole) { next hole += (current hole size - data size); // give extra space to next hole if (not last && next hole not occupied) current hole size = data size; //allocate full[current] = true; else { full[current] = true; break; Sample output Initial space allocation Hole e : e Hole 1: e Hole 2 : e -754973744 35544 41222336 41227488 Hole 3: e Hole 4 : e Enter data block size: 3 Allocated hole e Enter data block size: 4 Allocated hole 1 Enter data block size: 3 Allocated hole 2 Enter data block size: 5 Allocated hole 3 Enter data block size: 3 Allocated hole 4 All holes occupied? -771750959 input sizes {3,4,3,5,3} Test out some other data block sizes: true true true true true {8,3,2,2,1} {5,7,1,2,4} What are the Final space allocation Hole e : e Hole 1: e Hole 2: e Hole 3 : e -771750959 -771750959 35545 outputs? -771750959 -77175e959 35545 -754973744

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

need in C code

First fit algorithm
int n[5)=(4,3,8,2,3);
bool full[5] = {false, false, false, false, false};
// keep track of hole occupied
input data block size;
for(all holes)
if(found current hole size >= data size) && not occupied)
{ if (current hole size > data size && next hole not occupied && not last hole)
next hole += (current hole size - data size); // give extra space to next hole
if (not last && next hole not occupied)
{
current hole size = data size; //allocate
full[current] = true;
else
fullſcurrent] = true;
break;
Sample
output
Initial space allocation
Hole e : e
Hole 1:0
Hole 2 : 0
-754973744
35544
41222336
41227488
Hole 3 : 0
Hole 4: 0
Enter data block size: 3
Allocated hole e
input sizes Enter data block size: 4
Allocated hole 1
Enter data block size: 3
Allocated hole 2
Enter data block size: 5
Allocated hole 3
Enter data block size: 3
Allocated hole 4
All holes occupied?
-771750959
{3,4,3,5,3}
Test out some
other data
block sizes:
true
true
true
true
true
{8,3,2,2,1}
{5,7,1,2,4}
What are the
Final space allocation
Hole e : e
Hole 1: 0
Hole 2: 0
Hole 3 : e
Hole 4 : 0
-771750959
-771750959
35545
outputs?
-771750959
-771750959
35545
-754973744
-771750959
35545
-754973744
Transcribed Image Text:First fit algorithm int n[5)=(4,3,8,2,3); bool full[5] = {false, false, false, false, false}; // keep track of hole occupied input data block size; for(all holes) if(found current hole size >= data size) && not occupied) { if (current hole size > data size && next hole not occupied && not last hole) next hole += (current hole size - data size); // give extra space to next hole if (not last && next hole not occupied) { current hole size = data size; //allocate full[current] = true; else fullſcurrent] = true; break; Sample output Initial space allocation Hole e : e Hole 1:0 Hole 2 : 0 -754973744 35544 41222336 41227488 Hole 3 : 0 Hole 4: 0 Enter data block size: 3 Allocated hole e input sizes Enter data block size: 4 Allocated hole 1 Enter data block size: 3 Allocated hole 2 Enter data block size: 5 Allocated hole 3 Enter data block size: 3 Allocated hole 4 All holes occupied? -771750959 {3,4,3,5,3} Test out some other data block sizes: true true true true true {8,3,2,2,1} {5,7,1,2,4} What are the Final space allocation Hole e : e Hole 1: 0 Hole 2: 0 Hole 3 : e Hole 4 : 0 -771750959 -771750959 35545 outputs? -771750959 -771750959 35545 -754973744 -771750959 35545 -754973744
Create a memory allocation program to show the how the First Fit strategy would
allocate memory and move the spaces in memory.
Given the memory block size is 20 and initially
there are 5 holes with the sizes { 4, 3, 8, 2, 3}
After each allocation, if there are leftover space, the space can be given to the
next hole.
If there are 5 blocks of data with sizes {3,4,3,5,3}. Try to fit them in the block of
memory. How are the hole sizes changed as you allocate and shuffle the memory.
Use a dynamic array to represent hole size and print out the array to show hole size. For
example, the initial hole sizes are { 4, 3, 8, 2, 3}
Initial space allocation
Hole e : e
Hole 1 : e
Hole 2 : 0
-754973744
35544
41222336
41227488
Hole 3 : 0
Hole 4 : 0
-771750959
Pseudocode:
int n[5]={4,3,8,2,3};
int* arr = (int*) calloc(3, sizeof(int));
for (5 holes)
{
realloc(arr size to current hole size);
for(arr size)
print arr[);
}
Transcribed Image Text:Create a memory allocation program to show the how the First Fit strategy would allocate memory and move the spaces in memory. Given the memory block size is 20 and initially there are 5 holes with the sizes { 4, 3, 8, 2, 3} After each allocation, if there are leftover space, the space can be given to the next hole. If there are 5 blocks of data with sizes {3,4,3,5,3}. Try to fit them in the block of memory. How are the hole sizes changed as you allocate and shuffle the memory. Use a dynamic array to represent hole size and print out the array to show hole size. For example, the initial hole sizes are { 4, 3, 8, 2, 3} Initial space allocation Hole e : e Hole 1 : e Hole 2 : 0 -754973744 35544 41222336 41227488 Hole 3 : 0 Hole 4 : 0 -771750959 Pseudocode: int n[5]={4,3,8,2,3}; int* arr = (int*) calloc(3, sizeof(int)); for (5 holes) { realloc(arr size to current hole size); for(arr size) print arr[); }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY