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

Explanation of Solution

Implementation of “place()” function:

In the “Section 9.9.12 (mm.c)”, add the below “place()” function to allocate the blocks. The function “place()” is as follows:

// Definition of place() function to allocate the requested block

static void place(void *bp, size_t asize)

{

// Call GET_SIZE() function to assign csize

size_t csize = GET_SIZE(HDRP(bp));

// Check the size

if ((csize - asize) >= (2 * DSIZE)) {

// Call PUT function with HDRP and PACK asize, 1

PUT(HDRP(bp), PACK(asize, 1));

// Call PUT function with FTRP and PACK asize, 1

PUT(FTRP(bp), PACK(asize, 1));

// Call NEXT_BLKP() function to assign bp

bp = NEXT_BLKP(bp);

// Call PUT function with HDRP and computed PACK size, 0

PUT(HDRP(bp), PACK(csize - asize, 0));

// Call PUT function with FTRP and computed PACK size, 0

PUT(FTRP(bp), PACK(csize - asize, 0));

}

// Otherwise

else {

// Call PUT function with HDRP and PACK csize, 1

PUT(HDRP(bp), PACK(csize, 1));

// Call PUT function with FTRP and PACK csize, 1

PUT(FTRP(bp), PACK(csize, 1));

}

}

Explanation:

The “place()” function is to allocate the requested block.

  • A pointer “bp” represents which place the block is allocated.
  • Call “GET_SIZE()” function to assign “csize”.
  • “if” statement to check the size to fit the block.
    • The function “HDRP()” and “FTRP()” represents the place of the pointer.
    • Compute the size by calling “PACK()” function.
    • Place the block if the condition is satisfied using “PUT()” function.

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
C++
In C++
C++ 13.10 Write a function SwapArrayEnds() that swaps the first and last elements of the function's array parameter. Ex: sortArray = {10, 20, 30, 40} becomes {40, 20, 30, 10}. #include <iostream>using namespace std; /* Your solution goes here  */ int main() {   const int SORT_ARR_SIZE = 4;   int sortArray[SORT_ARR_SIZE];   int i;   int userNum;    for (i = 0; i < SORT_ARR_SIZE; ++i) {      cin >> userNum;      sortArray[i] = userNum;   }    SwapArrayEnds(sortArray, SORT_ARR_SIZE);    for (i = 0; i < SORT_ARR_SIZE; ++i) {      cout <<  sortArray[i] << " ";   }   cout << endl;    return 0;}
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