Question: C programming Task 1: Construct your own Implicit free list. Your custom memory allocator function could be custom_malloc(size, id) and custom_free(id). Where id would be
C programming
Task 1: Construct your own Implicit free list. Your custom memory allocator function could be custom_malloc(size, id) and custom_free(id). Where id would be identification number of any malloc request. You can assume that each of your block has the following structure (simple linked list):
struct block
{ int id;
struct block *next_list; //next start of the other list
struct block *next; //next block int list_size; //the length of the list, if this is the starting block
bool has_assigned; //list reserved or not
}
typedef struct block BLOCK;
For this assignment assume that, your heap size (Total block number) is 100. And initially all of your blocks are empty
do the following:
10 requests of custom_malloc(10, id). Where id is the index of the for loop.
After the first step, If the id is divided by 2, then call custom_free(id)
After that, you need to show the implicit free list you got, after that sequence of operations mentioned above.
Sample Output:
List starts at 0 is not allocated
List starts at 10 is allocated
List start at 20 is not allocated
List starts at 30 is allocated.
Task 2: Implement Next fit on your Implicit Free List.
The second task would be implement the Next fit policy for a sequence of custom_malloc operations. For example, the sequence of Input could be:
custom_malloc(5, id)
custom_malloc( 2,id)
custom_malloc (8, id)
And at the end you need to show the implicit free list of the blocks, as mentioned above (Sample Output).
In the First fit policy, the allocator would search for empty blocks which can fit the request. If it finds one, returns that list.
In the Next fit policy, instead of searching from the beginning of the free lists, it would start searching from where the previous search left off.
In the Best fit policy, it would search each of the free blocks and return the blocks which fits the request and has the smallest size among all.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
