Explanation of Solution
Implementation of “find_fit()” function with First-fit search:
In the “Section 9.9.12 (mm.c)”, add the below “find_fit()” function. The function “find_fit()” is as follows:
// Definition of find_fit() function to find a block fit with size bytes
static void *find_fit(size_t asize)
{
// First-fit search
// Declare the pointer
void *bp;
// For loop to find the fit for first block
for (bp = heap_listp; GET_SIZE(HDRP(bp)) > 0; bp = NEXT_BLKP(bp)) {
// Check the allocation and size
if (!GET_ALLOC(HDRP(bp)) && (asize <= GET_SIZE(HDRP(bp)))) {
// Return the point
return bp;
}
}
// Return null if no fit is available
return NULL;
}
Explanation:
The “find_fit()” function is to find a block fit with size bytes.
- Declare a pointer “bp” to represent which place the block is allocated.
- “for” loop to search the place to fit the first block.
- “if” statement to check the place and size to fit the block.
- Return the pointer.
- Otherwise, return “NULL” if no fit is available.
- “if” statement to check the place and size to fit the block.
The “find_fit()” function is used to implement other simple implicit-list allocator same as first-fit search and to handle and traverse blocks.
Filename: main.c
// Include libraries
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
// Include required header files
#include "csapp.h"
#include "memlib.h"
#include "mm.h"
#include "memlib.c"
#include "mm...
Want to see the full answer?
Check out a sample textbook solutionChapter 9 Solutions
EBK COMPUTER SYSTEMS
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY