Computer Systems: A Programmer's Perspective (3rd Edition)
Computer Systems: A Programmer's Perspective (3rd Edition)
3rd Edition
ISBN: 9780134092669
Author: Bryant, Randal E. Bryant, David R. O'Hallaron, David R., Randal E.; O'Hallaron, Bryant/O'hallaron
Publisher: PEARSON
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
Students have asked these similar questions
Exercise 1: Memory Allocation in C a) Write a C program which dynamically allocates memory to define an integer 5 x 5 matrix initialized to zero by using the calloc function. Do not forget to free the memory in the end of your program. b) What happens if you attempt to print your matrix before and after freeing memory?
VII.Let A = {2, 4, 6, 8}, B = {6, 9}, C = {4, 8}. Answer each of the following questions. Justify your answers. 1. Is B ⊆B?
3. The diagram below shows the main land routes for vehicular traffic between points A and G in a city. The figures in the arcs represent the cost of traveling between each pair of nodes.   a) Manually apply Dijkstra's algorithm to find the cheapest route between A and G (visited nodes and total distance). b) Formulate a linear programming problem in extended form, to determine the shortest route to travel from A to G. Do not use subscripts, name 14 variables, for example XFE would be the variable that indicates that the arc from F to E is used. c) If there is a fixed cost for visiting each node, modify the formulation of the problem to include said fixed cost in the objective function, and the variables and restrictions that are required.     NODE A B C D E F G FIXED COST 25 18 32 20 28 18 34
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning