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 program for y in line 2? 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?
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 now
This is a popular solution!
Step by step
Solved 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