Now, consider the real world on a 32-bit computer with byte-addressable memory.
ID: 3545831 • Letter: N
Question
Now, consider the real world on a 32-bit computer with byte-addressable memory. Initially, the heap is empty. The only memory allocated is an array of 28 null pointers. freelists[3]holds the free list of 8-byte blocks, the smallest size supported, while freelists[31] holds the list of 2-gigabyte blocks, the largest size supported. (There can be no 4-gigabyte blocks because at least one byte of the RAM must be occupied by the code of the heap manager, preventing the entire memory from ever being listed in the free list.)
If this system is on a UNIX machine, the heap manager will add memory to the heap whenever the current heap does not have the free space needed to meet the demand of a call tomalloc(). Memory is added to the heap by calling sbrk() to allocate a block sized to the next power of two greater than twice the size requested by malloc().
a) Does this guarantee that the heap manager will be able to treat the new block as a single free block? Why or why not?
b) It is always possible that a user program will call sbrk() directly between two different calls to malloc(). As a result, it is possible that the heap will not be a single contiguous block of free space, but will, instead, contain gaps that are not under the heap manager's control. Does this cause any problems under the buddy system as discussed in class? explain.
Explanation / Answer
a>.
No, the heap manager will not be able to treat the new block as a single free block. Because when the current heap doesn't have any free space, two consiquitive new call to tomalloc() will result in creation of uncontiguious memory alocation. means the space available will be in discreate and in disjoint set. So the heap manager will not be able to treat the new block as a single free block.
b>.
yes, the buddy system will face the problem of memory westage. When the number of gaps increases then the heap will not be a single contiguous block of free space, resulting in the situation that though the spaces of memory are free in the form of gaps, Heap manager will not be able to allocate these storage. Thus resulting in poor memory utilization and a complete westage of memory space.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.