Question
Next Fit Memory Allocation in C Make your own malloc and free functions using a doubly linked list to track the nodes in the heap.
Next Fit Memory Allocation in C
Make your own malloc and free functions using a doubly linked list to track the nodes in the heap. The following struct will serve as the header for each linked list node:
typedef struct Node{
int size;
int free;
struct Node* next;
struct Node* prev;
} Node;
And three globals called, first, last, curr, that keeep track of the first allocated block on heap, final allocated block on heap, and the current position of the block that was last allocated on the heap.
Make a malloc() next fit memory allocation scheme in function: void* my_next_fit_malloc(int size). this function should allocate memory using a next fit allocation scheme. If there is no empty space in the heap allocate more using sbrk(). Use of multiple functions encouraged.
And a free() function called: void my_free(void* ptr) to dellocate memory.
Write a test file to test these my_free and my_malloc functions.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started