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...
Want to see the full answer?
Check out a sample textbook solutionChapter 9 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
- c) (6 points) For each of the following scenarios choose the "best" data structure from the following list or a combination of data structures: an unsorted array, linked list, DLL, circular LL, stack, queue. In each case, justify your answer briefly. i. Suppose that a grocery store decided that customers who come first will be served first. ii. A list must be maintained so that any element can be accessed randomly. iii. A program needs to remember operations it performed in opposite order.arrow_forward(C++) I need a quicksort algorithm implementation which returns the indices of the sorted array in an array without modifying the array itself:ie,Before sortingindex : 0 1 2 3 4 5values: 70 60 40 20 30 50After sortingindex : 3 4 2 5 1 0values: 70 60 40 20 30 50 function returns an array with indexes: [3 4 2 5 1 0]arrow_forwardC++ 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;}arrow_forward
- #17a Simple Statistics (not in textbook) Generate a STL array or vector of 1000 floating point numbers in the range 0 to 1. Compute the mean, median, and standard deviation of these. You may use function objects and lambda expressions, and the STL algorithms for_each, accumulate, and sort. You may not use any of the built-in looping constructs while, do-while or for. Also you may not create and use any ordinary c++ functions. Hint: The following code can be used to populate your random array named arr auto arr_store = [](float& v) { v = rand()/float(RAND_MAX); }; for_each(arr.begin(),arr.end(),arr_store); Warning, You may need to know some details about lambda expressions that are not covered in the textbook. These will be covered in the weekly lecture and in a sample program in Sakai resources. Note: The theoretical value of the standard deviation for large N is sqrt(1.0/12) which about 0.289. You should be getting a value fairly close to this.arrow_forward(python) 11. Create a function based on the following information: There is a list which contains integers or other nested lists which may contain yet more lists and integers which then… you get the idea. You should put all of the integer values into one flat list. The order should be as it was in the original list with string representation from left to right. [1, 2, [ 3, 4], [5,6]] ==> [1, 2, 3, 4, 5, 6] Input data: A nested list with integers. Output data: Nothing to output Return: The one-dimensional list with integers.arrow_forwardc++ (1) Create a function capable of multiplying a row of a matrix by a given number. Do the same for a columnarrow_forward
- (5.1) In the context of designing a system that offers a file management capability, e.g., OneDrive, there are some constraints on the acceptable file names. The following three characters {*,$, :} in addition to spaces are not allowed in file names. If any of these four characters appears in a file name, it is replaced by a hyphen (-). Examples: "new file" → "new-file" "important$file" → "important-file" "abc$def gh:ij*klm.txt" → "abc-def-gh-ij-klm.txt" "exam.doc" →→ "exam.doc" i. Design an algorithm that takes a file name as a string and returns a modified name replacing the prohibited characters with hyphens. Use pseudocode to describe your algorithm. Define all operations that are used in your algorithm. ii. What is the runtime complexity of your algorithm?arrow_forward14.7 Practice using C++ hash templates C++ has two built in hash structures that will suite for most programming needs of hashes. The two types are unorderedmap and orderedmap. In this weeks program you are going to practice creating, inserting and iterating over the two types of maps. Your assignment is to create an unordered map and an ordered map, both with have key value pairs of type . You will read the key value pairs in from a dataFile using the file stream operator storing the first value (an integer into the integer key) and the second one into a string. You will then insert each pair into both the unordered and ordered maps. Lastly you will use an interator to iterate through the map printing them out. Your output should make it clear by label which list is the ordered map and which is the unordered map. The test provided is merely for your assistance - your program will be graded on it's content regardless of the results of book test. You will need the following references…arrow_forwardThe programming language: C++ The union of two ordered lists (Sequential linear list)[the solution introduction: The first video of in 3.1, 35:00-43:00] [Problem description] Give the union of two ordered lists. The maximal number of elements in an inputted set is 30. [Basic requirements] 1) Use sequential linear list. 2) The result list should also be ordered. [Example] Problem: Give the union of the ordered lists (3,4,9,100,103) and (7,9,43,53,102,105). What you need to show in the terminal(the back part is outputted by you and the blue part is inputted by the user, i.e., teacher): Please input the first ordered list: (3,4,9,100,103)Please input the second ordered list: (7,9,43,53,102,105) The union is: (3,4,7,9,9,43,53,100,102,103,105)arrow_forward
- Solve the problem using C++ (Evaluate expression) Modify Listing 12.12 EvaluateExpression.cpp to add operators ^ for exponent and % for modulus. For example, 3 ^ 2 is 9 and 3 % 2 is 1. The ^ operator has the highest precedence and the % operator has the same precedence as the * and / operators. Sample Run Enter an expression: (5 * 2 ^ 3 + 2 * 3 % 2) * 4 (5 * 2 ^ 3 + 2 * 3 % 2) * 4 = 160arrow_forward(Java) Activity 4.1 *** COMPLETE COMPARISONS 5,7,8,9! The rest are already done for you! Open up MS Word or another text editor, create a new text document named trace, with a doc, docx, odt, or txt extension Then trace bubble sort on the following array. You must show intermediate steps, labeled below as "Comparisons" - i.e. show what happens when two elements are compared to each other - show them as swapped or not swapped. To save yourself unnecessary work, use the more efficient version of bubble sort. Hint: Use copy and paste to your advantage. Please highlight the two elements being compared in some way (underline, bold, or italicize them, or place brackets around them) Trace bubble sort on the following array of data. int A[] = { 12, 3, 19, 14, 2}; Comparison 1: 3 12 19 14 2 Comparison 2: 3 12 19 14 2 Comparison 3: 3 12 14 19 2 Comparison 4: 3 12 14 19 2 Comparison 5: Comparison 6: 3 12 14 2 19 Comparison 7: Comparison 8: Comparison 9: Comparison 10: 2 3 12 14 19…arrow_forwardC++ Programming. Topic: Working with pointers and dynamic memory. Indicators. Working with dynamic memory. Dynamic arrays and their use as function parameters. Task : Describe a void function named Swap(x,y) that swaps the values stored in the variables x and (x is a real type parameter and is both input and output). Using this function , for the given variables of real type a, b, c, d, one should sequentially replace the values of the pairs (a, b), (c, d) and (b, c) and let a, b, c, d be new values .arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education