EBK COMPUTER SYSTEMS
EBK COMPUTER SYSTEMS
3rd Edition
ISBN: 8220101459107
Author: O'HALLARON
Publisher: YUZU
Expert Solution & Answer
Book Icon
Chapter 9.9, Problem 9.8PP

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.

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...

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