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
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 9, Problem 9.17HW

Explanation of Solution

Perform Next-fit search instead of First-fit search:

In the “Section 9.9.12 (mm.c)”, remove the lines that starts from “/* $begin mmfirstfit */” and ends with “return NULL; /* No fit */”.

Add the following highlighted code to the “Section 9.9.12 (mm.c)”. The modified “mm.c” file is as follows:

/* Global variables */

static char *heap_listp = 0;  /* Pointer to first block */

// Rover for Next fit

static char *rover;

/* Function prototypes for internal helper routines */

static void *extend_heap(size_t words);

heap_listp += (2 * WSIZE);

/* $end mminit */

// Assign heap_listp to rover

rover = heap_listp;

/* $begin mminit */

/* Extend the empty heap with a free block of CHUNKSIZE bytes */

bp = PREV_BLKP(bp);

}

/* $end mmfree */

// If condition to check the rover is not representing the free block

if ((rover > (char *)bp) && (rover < NEXT_BLKP(bp)))

// Assign bp to rover

rover = bp;

/* $begin mmfree */

return bp;

}

{

/* Next fit search instead of first fit search*/

// Assign rover to the character pointer oldrover

char *oldrover = rover;

/* Finding next fit using for loop */

// For loop to search from rover to the end of the list

for (; GET_SIZE(HDRP(rover)) > 0; rover = NEXT_BLKP(rover))

// If condition to check allocation and size of rover

if (!GET_ALLOC(HDRP(rover)) && (asize <= GET_SIZE(HDRP(rover))))

// Return rover

return rover;

// For loop to search from start of list to old rover

for (rover = heap_listp; rover < oldrover; rover = NEXT_BLKP(rover))

// If condition to check allocation and size of rover

if (!GET_ALLOC(HDRP(rover)) && (asize <= GET_SIZE(HDRP(rover))))

// Return rover

return rover;

// Otherwise return null

return NULL;

}

/* $end mmfirstfit */

Filename: main.c

// Include libraries

#include <stdio.h>

#include <stdlib.h>

#include <assert.h>

// Include required header files

#include "csapp...

Blurred answer
Students have asked these similar questions
Write a class that maintains the top ten scores for a game application,implementing the add and remove methods of Section 3.1.1 in the textbook, but using a singly linked list instead of an array. You need to implement the singly linked list yourself. Textbook reference is Data structures and algorithms Micheal Goodrich
Implement a list of employees using a dynamic array of strings.Your solution should include functions for printing list, inserting and removingemployees, and sorting lists (use Bubble sort in C++ language).Keep list of employees sorted within the list after insertion.See the following example:How many employees do you expect to have?5 (Carriage Return)Menu :1 . Print full list of employees2 . Insert new employee3 . Remove employee from list0 . Exit2 (Carriage Return)Input name of new employee : MikeMenu :1 . Print full list of employees2 . Insert new employee3 . Remove employee from list0 . Exit1(Carriage Return)1 . MaryMenu :1 . Print full list of employees2 . Insert new employee3 . Remove employee from list0 . Exit
Import the ArrayList and List classes from the java.util package to create a list of phone numbers and also import the HashSet and Set classes from the java.util package to create a set of unique prefixes. Create a class called PhoneNumberPrefix with a main method that will contain the code to find the unique prefixes. Create a List called phoneNumbers and use the add method to add several phone numbers to the list. List<String> phoneNumbers = new ArrayList<>(); phoneNumbers.add("555-555-1234"); phoneNumbers.add("555-555-2345"); phoneNumbers.add("555-555-3456"); phoneNumbers.add("444-444-1234"); phoneNumbers.add("333-333-1234"); Create a Set called prefixes and use a for-each loop to iterate over the phoneNumbers list. For each phone number, we use the substring method to extract the first 7 characters, which represent the prefix, and add it to the prefixes set using the add method. Finally, use the println method to print the prefixes set, which will contain all of…
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
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