Assume we have a free space management system as described in the book, for example one used to provide us with virtual addresses on the heap (with physical addresses handled by a much simpler system since we assume paging). Assume the system uses the following very simple rules;
- A memory request traverses the free list, and finds the first block large enough to handle the request (i.e., the first fit
algorithm from the book). It then:- Splits the block into 2 pieces: The first piece will be the requested size + 1k (for a header). The second will be the remaining
- The first piece will be returned to the caller, but the address returned will be the address of the memory for the user, that is the header + 1k
- The second will be put back into the linked list
- If there's insufficient contiguous memory, the allocation will fail (return 0)
- Free memory is stored as a linked list in address order
Assume we start with a single contiguous block of FREE memory of size 64k starting at location 32k in memory. Consider the following sequence of mallocs and frees:
1 | x = malloc(7168); /* 7k */ |
2 | y = malloc(5120); /* 5k */ |
3 | z = malloc(11264); /*11k */ |
4 | free(x); |
5 | x = malloc(8192); /* 8k */ |
6 | free(y); |
7 |
y = malloc(12288); /* 12k */ |
8 | free(z); |
9 | z = malloc(38912); /* 38k */ |
Please fill in the requested addresses. Note that since everything is in k, you may use raw numbers (e.g., 1024) or the equivalent k (e.g., 1k).
The address returned to the caller for x in line 1?
The address returned to the
The address returned to the program for z in line 3?
The address reclaimed by the OS in line 4 (hint: This may not be the same as the address of x)?
The address returned to the program for x in line 5?
The address reclaimed by the OS in line 6 (hint: This may not be the same as the address of y)?
The address returned to the program for y in line 7?
The address reclaimed by the OS in line 8 (hint: This may not be the same as the address of z)?
The address returned to the caller for z in line 9?
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps
this is what my professor said:
1. Memory starts at 32k, but we always have a leading 1k header, so 33k will be returned. Your reclaim (in 4) however, will reclaim the header too, so that will be 32k. You missed this. In step ~5 however, you state that there's room for 8k at 32, but you actually need 9k (8k+1) and don't have it.
Can someone please fix this and give me all the answers again?
In the previous answers:
Isn't 1 is supposed to be subtracted from the 64 as well?
-
Malloc for x:
- Requested size: 10k
- Address returned to the caller: 32k + 1k = 33k (since x will be placed after the header of 1k)
- Address returned to the program: 33k
- Remaining free memory: 54k (64k - 10k) (here)
- Address of the remaining free memory: 43k
and
Here, the requested size is 20, why is 10 subtracted?
-
Malloc for y (again):
- Requested size: 20k
- Address returned to the caller: 44k (previous address)
- Address returned to the program: 44k (previous address)
- Remaining free memory: 54k (64k - 10k) (here)
- Address of the remaining free memory: 64k
The address returned to the caller of z on line 9 is 33792 (beginning of free memory block) + 1k (header) = 34816.
this doesn't follow the line 5 and line 7.
Could you please explain why 33792 returned to in line 9 and 32k in line 5 and 7?
thank you
this is what my professor said:
1. Memory starts at 32k, but we always have a leading 1k header, so 33k will be returned. Your reclaim (in 4) however, will reclaim the header too, so that will be 32k. You missed this. In step ~5 however, you state that there's room for 8k at 32, but you actually need 9k (8k+1) and don't have it.
Can someone please fix this and give me all the answers again?
In the previous answers:
Isn't 1 is supposed to be subtracted from the 64 as well?
-
Malloc for x:
- Requested size: 10k
- Address returned to the caller: 32k + 1k = 33k (since x will be placed after the header of 1k)
- Address returned to the program: 33k
- Remaining free memory: 54k (64k - 10k) (here)
- Address of the remaining free memory: 43k
and
Here, the requested size is 20, why is 10 subtracted?
-
Malloc for y (again):
- Requested size: 20k
- Address returned to the caller: 44k (previous address)
- Address returned to the program: 44k (previous address)
- Remaining free memory: 54k (64k - 10k) (here)
- Address of the remaining free memory: 64k
The address returned to the caller of z on line 9 is 33792 (beginning of free memory block) + 1k (header) = 34816.
this doesn't follow the line 5 and line 7.
Could you please explain why 33792 returned to in line 9 and 32k in line 5 and 7?
thank you
- Draw a memory map for the code you see on the next page, until the execution reaches the point indicated by the comment /* HERE */.In your diagram:• You must have a stack, heap, and static memory sections • Identify each frame as illustrated by the previous examples.• Draw your variables as they are encountered during program execution. Code: public class Passenger {private String name;private int ticketCost;private StringBuffer luggage;private static final int LUGGAGE_COST = 20;public Passenger(String name, int ticketCost) {this.name = name;this.ticketCost = ticketCost;luggage = new StringBuffer();}public Passenger addLuggage(String desc) {ticketCost += LUGGAGE_COST;luggage.append(desc);return this;}public int getTicketCost() {return ticketCost;}public Passenger reduceCost(int by) {ticketCost -= by;/* HERE */return this;}public String toString() {return "Passenger [name=" + name + ", ticketCost=" + ticketCost + ", luggage=" + luggage + "]";}}public class Driver {public static void…arrow_forwardIn §12.2 Lamport's Hash we mentioned the notion of using only 64 bits of the hash. At each stage, 128 bits are computed, 64 bits are thrown away, and the hash of the retained 64 bits is used in the next stage. The purpose of only using 64 bits is so that a human does not need to type as long a string. Assuming the person will still only type 64 bits, does it work if hashn does a hash of all 128 bits of hashn-1, but what the person actually transmits is 64 bits of the result?arrow_forwardWrite a Java program that generates randomly a list of N integers, sorts the generated list using each of the three sorting algorithms: mergesort sort, quicksort that use the first element as a pivot, and quicksort that use the middle element as pivot and prints as output the execution time for each of the algorithms for randomly generate lists of size N = 40000, 100000 and 200000 and sorted lists as shown in the table.arrow_forward
- S1 and S2 are two sorted stacks of n and m numbers sorted in decreasing order, with their top items pointing to the smallest in their lists, respectively. Create a stack MERGE that merges the items in stacks S1 and S2, so that at the conclusion of the merge, all of the elements in S1 and S2 are available in MERGE in decreasing order, with the largest element at the top.Keep in mind that the number of components in stack MERGE is (n + m).arrow_forwardUSING C LANGUAGE IN NETBEANS : Write a program menu that creates and manages Fibonacci heaps. The program must implement the following operations: creation, insertion, find min, extract min, decrease key, and deletion. **NOTE: The program should present a menu where user may choose from implemented options.arrow_forward2.2.14 Sorted queues being combined. Create a static function that receives two queues of sorted items as inputs and returns a queue formed by combining the two queues into a single sorted order queue. 2.2.15 Bottom-up mergesort of a queue. Create an implementation of the bottom-up mergesort using the following strategy: Make N queues, each holding one of the N things, given N items. assemble the N queues into a queue. Apply Exercise 2.2.14's merging process to the first two queues several times, and at the conclusion, reinsert the combined queue.Continue until there is just one queue left in the queue of queues.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