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.
- “if” statement to check the place and size to fit the block.
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...
Want to see the full answer?
Check out a sample textbook solutionChapter 9 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
- Problem Statement: Consider an input string TAM of letters ‘A’, ‘M’, and ‘T’. This string, which is given by the user, ends with ‘#’. It should be stored in a table (or array), called TAMUK. The number of each of these letters is unknown. We have a function, called SWAP(TAM,i,j), which places the ith letter in the jth entry of string TAM and the jth letter in the ith entry of TAM. Note that SWAP(TAM,i,j) is defined for all integers i and j between 0 and length(TAM)–1, wherelength(TAM) is the number of letters of TAM. Using our algorithmic language, write an algorithm, called Sort_TAM, which sorts the letters in the array TAMUK in a way that all T’s appear first, followed by all A’s, and followed by all M’s. The algorithm Sort_TAM should have one parameter: The array TAMUK. Also, your solution is correct only if the following four constraints are satisfied: - Constraint 1: Each letter (‘A’, ‘M’, or ‘T’) is evaluated only once. - Constraint 2: The function SWAP(TAM,i,j) is used…arrow_forwardProblem Statement: Consider an input string TAM of letters ‘A’, ‘M’, and ‘T’. This string, which is given by the user, ends with ‘#’. It should be stored in a table (or array), called TAMUK. The number of each of these letters is unknown. We have a function, called SWAP(TAM,i,j), which places the ith letter in the jth entry of string TAM and the jth letter in the ith entry of TAM. Note that SWAP(TAM,i,j) is defined for all integers i and j between 0 and length(TAM)–1, where length(TAM) is the number of letters of TAM. 1. Using our algorithmic language, write an algorithm, called Sort_TAM, which sorts the letters in the array TAMUK in a way that all T’s appear first, followed by all A’s, and followed by all M’s. The algorithm Sort_TAM should have one parameter: The array TAMUK. Also, your solution is correct only if the following four constraints are satisfied: - Constraint 1: Each letter (‘A’, ‘M’, or ‘T’) is evaluated only once. - Constraint 2: The function SWAP(TAM,i,j) is used only…arrow_forwardProblem Statement: Consider an input string TAM of letters ‘A’, ‘M’, and ‘T’. This string, which is given by the user, ends with ‘#’. It should be stored in a table (or array), called TAMUK. The number of each of these letters is unknown. We have a function, called SWAP(TAM,i,j), which places the ith letter in the jth entry of string TAM and the jth letter in the ith entry of TAM. Note that SWAP(TAM,i,j) is defined for all integers i and j between 0 and length(TAM)–1, where length(TAM) is the number of letters of TAM. 1. Using our algorithmic language, write an algorithm, called Sort_TAM, which sorts the letters in the array TAMUK in a way that all T’s appear first, followed by all A’s, and followed by all M’s. The algorithm Sort_TAM should have one parameter: The array TAMUK. Also, your solution is correct only if the following four constraints are satisfied: - Constraint 1: Each letter (‘A’, ‘M’, or ‘T’) is evaluated only once. - Constraint 2: The function SWAP(TAM,i,j) is used only…arrow_forward
- (Practice) Run Program 7.10 to determine the average and standard deviation of the following list of 15 grades: 68, 72, 78, 69, 85, 98, 95, 75, 77, 82, 84, 91, 89, 65, and 74.arrow_forward5. (a) Write a function that solves the general linear least-squares problem. The inputs to your function should be a vector of a values, a vector of measured y values, and an anonymous function that calculates a single row of the Z matrix. Inside your function, use the inputted anonymous function to create Z row-by-row, then use Z to create the normal equations. Solve these normal equations to obtain the computed coefficients that define the best-fit of your model. Your function should output these calculated coefficients. Again, include an error check that makes sure the input vectors are the same size. You may not use any built-in MATLAB functions to solve the normal equation. You can use any functions you have developed solves Ax = b via LU-decomposition is one option. e.g. a function you have that (b) Test your function in (a) to fit the following model to the given dataset (see belo y = a + bx (c) Test your function in (a) to fit the following model to the given dataset…arrow_forwardHow do I code Fibonacci Function in C program? I need to only print out by 5 each Fibonacci number (0, 5, 10, 15, 20, 25, 30, 35, 40, 45). This is associated with recursion, while a direct code solution exists using loops, recursion needs to be used.arrow_forward
- make this code work able instruction are given in picture #include<math.h> using namespace std; double lerpSingle(double a, double b, double t) { if (t <= 0.5) return a+(b-a)*t; else return b-(b-a)*(1.0-t); } // This is for linear interpolation Vector3 lerp(Vector3 u, Vector3 v, double t) { return Vector3(lerpSingle(u.x, v.x, t), lerpSingle(u.y, v.y, t), lerpSingle(u.z, v.z, t)); } // This is for identifying if 4 vectors are coplanar bool coplanar(Vector3 p, Vector3 q, Vector3 r, Vector3 s) { Vector3 ab = Vector3(q.x-p.x, q.y-p.y, q.z-p.z); Vector3 bc = Vector3(r.x-q.x, r.y-q.y, r.z-q.z); Vector3 cd = Vector3(s.x-r.x, s.y-r.y, s.z-r.z); if (dot(cross(ab,bc), cd) == 0) { return true; } else { return false; } } Below are the helper function I have used for your reference double dot(Vector3 u, Vector3 v) { double product = 0; product = u.x*v.x + u.y*v.y + u.z*v.z; } Vector3 cross(Vector3 u, Vector3 v) { double x = u.y * v.z - u.z * v.y; double y = u.z * v.x - u.x * v.z;…arrow_forward(Practice) a. Write a C++ program that adds the values of all elements in the val array used in Exercise 2 and displays the total. b. Modify the program written for Exercise 3a to display the total of each row separately.arrow_forwardProblem 4 We can use lists of numbers like l to represent a mathematical vector. Recall from math classes that a vector is an object with a magnitude and direction. The magnitude is the sqrt of the sum of the squares (for a vector (x,y) it's the Pythagorean theorem for the magnitude (x^2 + y^2)**(1/2)). For a vector of any other length, the formula generalizes to (l[0]^2 + l[1]^2 + l[2]^2 + ... )**(1/2). For this problem use l from Problem 1 and a for loop to compute the magnitude of l with the result stored in l_mag. For l above, its magnitude is 12.96. Python gives you the ** exponentiation operator to raise a number to a power. You could also import math and use math.sqrt(). l = [1, 2, 3, 4, 5, 7, 8] Please give proper explanation and typed answer only.arrow_forward
- For each of the following problems, all functions should be implemented using a call stack. Problem 2: Write a program that defines two integer array that are pre-sorted and the same size (e.g., [3, 7, 9, 11, 15, 21] and [1, 4, 6, 14, 18, 19]) and a function merge that takes the two arrays (and their size) as inputs and populates a single array of twice the size of either input array that contains the elements of both arrays in ascending order. In the example arrays given, then output would be [1, 3, 4, 6, 7, 9, 11, 14, 15, 18, 19, 21]. Have your 'main' function (not the merge function) print out the final array using a comma as a delimiter.arrow_forward1. (a) Write a recursive o function for performing binary search on an array of integer. Show how to use this function with sample call from main(). For an input array A={2,6,8,14, 18, 19,37,46, 77}, show each step of algorithm when searching for the value (i) 46 (ii) 17 in the array. (b) Give a structure for storing a active COVID cases in a state. It should consist of the state name (20 characters)and number of active COVID 19 cases (integers) in each state. Each of the 250 students of Btech 1st year (all sections). Inside main () create and array of structure type for holding this information. Write a function that sorts this array in ascending order of active COVID 19 cases, so that we can rank the states in order of the number of cases in each state of the country. (c) Write a function called input() that reads the content of 2-D array( A matrix) row by row. Write a second C function called mult() that takes two matrices and their dimensions as argument and computes. Their…arrow_forward6. Consider the following Java program, which is suppose to compute the transpose of a given 4 x 4 matrix M. Note: there is an X in the program, which indicates some missing statements. Choose the correct option to replace X in the program. #include<java.util.*>#define ROW 4#define COL 4int M[ROW][COL] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};main(){int i, j, t;for (i = 0; i < 4; ++i){X}for (i = 0; i < 4; ++i)for (j = 0; j < 4; ++j)System.out.println ("%d", M[i][j]);}arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning