Computer Systems: A Programmer's Perspective Plus Mastering Engineering With Pearson Etext -- Access Card Package (3rd Edition)
Computer Systems: A Programmer's Perspective Plus Mastering Engineering With Pearson Etext -- Access Card Package (3rd Edition)
3rd Edition
ISBN: 9780134123837
Author: Randal E. Bryant, David R. 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
6. What is Race condition? How to prevent it? [2 marks] 7. How many synchronization methods do you know and compare the differences. [2 marks] 8. Explain what are the “mutual exclusion”, “deadlock”, “livelock”, and “eventual entry”, with the traffic intersection as an example like dinning philosophy. [2 marks] 9. For memory allocation, what are the difference between internal fragmentation and external fragmentation. Explain with an example. [2 marks] 10. How can the virtual memory map to the physical memory. Explain with an example. [2 marks]
Your answers normally have 50 words. Less than 50 words will not get marks. 1. What is context switch between multiple processes? [2 marks] 2. Draw the memory layout for a C program. [2 marks] 3. How many states does a process has? [2 marks] 4. Compare the non-preemptitve scheduling and preemptive scheduling. [2 marks] 5. Given 4 process and their arrival times and next CPU burst times, what are the average times and average Turnaround time, for different scheduling algorithms including: a. First Come, First-Served (FCFS) Scheduling [2 marks] b. Shortest-Job-First (SJF) Scheduling [2 marks] c. Shortest-remaining-time-first [2 marks] d. Priority Scheduling [2 marks] e. Round Robin (RR) [2 marks] Process Arrival Time Burst Time P1 0 8 P2 1 9 P3 3 2 P4 5 4
a database with multiple tables from attributes as shown above that are in 3NF, showing PK, non-key attributes, and FK for each table? Assume the tables are already in 1NF. [Hint: 3 tables will result after deducing 1NF -> 2NF -> 3NF]
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr