Dynamic memory allocation. An allocator is working with a heap size of 16 KB. The blocks it returns for malloc() requests are aligned at 8B boundaries. It uses the header and footer structures discussed in the lectures. The request sequence from the mutator is as follows, where malloc() is abbreviated as M() and free() as F().
P1 = M(100);
P2 = M(200);
P3 = M(400);
F(P2);
P2 = M(800);
P4 = M(2048);
F(P1);
F(P3);
P1 = M(1000);
F(P4);
P3 = M(100);
What are the values returned by the malloc() calls if the
allocator uses the following design choices?
(a) Explicit free list, first fit, splitting, immediate
coalescing.
(b) Explicit free list, first fit, splitting, deferred
coalescing.
(c) Explicit free list, first fit, splitting, no coalescing.
(d) Explicit free list, next fit, splitting, immediate
coalescing
Please explain your answer as well.
Dynamic memory allocation is the memory management technique which utilises the functions such as malloc(), realloc(), calloc(), and free() along with the fitting allotments as best fit, first fit, worst fit and next fit.
In the given Scenario:
P1 = M(100);
P2 = M(200);
P3 = M(400);
F(P2);
P2 = M(800);
P4 = M(2048);
F(P1);
F(P3);
P1 = M(1000);
F(P4);
P3 = M(100);
The correct choice will be (a) Explicit free list, first fit, splitting, immediate coalescing, because from the beginning P1, P2, P3 allocated (heap size 16kB and malloc request size 8B are given), after these allotment P2 free the memory space and require 800 space which is not present at the P2 location so, it will immediately allocate the space which is freely available and able to accomodate the entire process P2. Then allocate the space for P4, then perform free(P1) AND free(P3), Again perform allocation to process P1 and free(P4). For the processing will be same as previous and lastly again perform allocation for process P3.
Get Answers For Free
Most questions answered within 1 hours.