EBK COMPUTER SYSTEMS
EBK COMPUTER SYSTEMS
3rd Edition
ISBN: 8220101459107
Author: O'HALLARON
Publisher: YUZU
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
Knowledge Booster
Background pattern image
Computer Engineering
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY