Question: 1 . Draw the following figures: a . Draw a figure similar to that on p . 2 4 5 of your text, showing the
Draw the following figures:
a Draw a figure similar to that on p of your text, showing the stack after the following sequence of operations:
StackAllocatr s new StackAllocatr;
spush;
spush;
spush;
b Draw a figure similar to that on p of your text, showing the heap after the following sequence of operations:
HeapAllocatr h new HeapAllocatr;
int x hnewH;
int y hhewH;
hdeleteHx;
int z hnewH;
This is one of the simplest mechanisms for heap management: first fit, with a free
list in lastinfirstout order. Consider a HeapManager m with a memory array of
words, and look at the following sequence of calls:
pm allocate ;
pmallocate ;
m deallocate p;
pmallocate ;
The following illustration shows an initial, empty memory array of words. The
heap manager maintains a variable called freestart, which is a link to the head
of the linked list of free blocks. Initially, the entire memory array is one big free
block:
Every block in the heap, whether allocated or free, has its length in its first word.
For free blocks, the second word is also used. It is the address of the next free block
in the free list. The value is used to represent the null link, the link from the last
block in the list.
The running program now makes its first allocation, pm allocate The
heap manager finds that the first and only block in the free list is large enough.
In fact, it is too large. The heap manager allocates five words the requested four
plus one for the length word and returns the remainder to the free list. The address
returned to the running program is the first of the four requested words.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
