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
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...
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F5e1132c9-beab-4f38-876e-7cf6bf6331b8%2F923b15b3-bb3d-4d2a-b3c0-f5fb77e52d92%2F72prymf_processed.jpeg&w=3840&q=75)
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[);
}](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F5e1132c9-beab-4f38-876e-7cf6bf6331b8%2F923b15b3-bb3d-4d2a-b3c0-f5fb77e52d92%2F669q1p_processed.jpeg&w=3840&q=75)
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
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Recommended textbooks for you
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
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…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
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)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
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…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
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)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
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](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY