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
(QI. 5.) Write a C++ class member function to print alternate nodes of the given Linked List, first from head to end, and then from end to head. If Linked List has even number of nodes, then function skips the node. (Example: Input: 1->2->3->4->5, output: 13553 1).
(Java) In this task, a skip list data structure should be implemented. You can follow the followinginstructions:- Implement the class NodeSkipList with two components, namely key node and arrayof successors. You can also add a constructor, but you do not need to add anymethod.- In the class SkipList implement a constructor SkipList(long maxNodes). The parameter maxNodes determines the maximal number of nodes that can be added to askip list. Using this parameter we can determine the maximal height of a node, thatis, the maximal length of the array of successors. As the maximal height of a nodeit is usually taken the logarithm of the parameter. Further, it is useful to constructboth sentinels of maximal height.- In the class SkipList it is useful to write a method which simulates coin flip andreturns the number of all tosses until the first head comes up. This number representsthe height of a node to be inserted.- In the class SkipList implement the following methods:(i) insert, which…
(IntelliJ) Write an easier version of a linked list with only a couple of the normal linked list functions and the ability to generate and utilize a list of ints.  The data type of the connection to the following node can be just Node, and the data element can be just an int. You will need a reference (Java) or either a reference or a pointer (C++) to the first node, as well as one to the last node. * Create a method or function that accepts an integer, constructs a node with that integer as its data value, and then includes the node to the end of the list.  If the new node is the first one, this function will also need to update the reference to the first node. This function will need to update the reference to the final node.  Consider how to insert the new node following the previous last node, and keep in mind that the next reference for the list's last node should be null. * Create a different method or function that iteratively explores the list, printing the int data values as…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education