Question
Please write C code for this memory allocation problem. Given are three files alloc.c , alloc.h and alloctest.c Your job is to write the freef()
Please write C code for this memory allocation problem.
Given are three files alloc.c , alloc.h and alloctest.c
Your job is to write the freef() function in the file alloc.c according to the pseudocode given below :
The files are posted at the link because they are quite large to post it here. Please copy and paste it to the browser .
Alloc.c
https://justpaste.it/1l5fo
alloc.h
https://justpaste.it/2b2db
alloctest.c
https://justpaste.it/6r5b7
Put this files together and all you have to do is write freef() function in file alloc.c where it says "/* you write the code for the freef function here */
?
Pseudocode for freef(char *p) p is the same pointer obtained from alloc) Change tag to FREETAG on blockl Change tag to FREETAG on blockr No need to update size on blockl and blockr because alloc() sets the sizes correctly Check if block on left is also free? case 1: yes, coalesce free block on left and p case 2: no, enchain buffer Check if block on right is also free? case 3: yes, unchain the block on right and coalesce p with block on right. return Pseudocode for freef(char *p) p is the same pointer obtained from alloc) Change tag to FREETAG on blockl Change tag to FREETAG on blockr No need to update size on blockl and blockr because alloc() sets the sizes correctly Check if block on left is also free? case 1: yes, coalesce free block on left and p case 2: no, enchain buffer Check if block on right is also free? case 3: yes, unchain the block on right and coalesce p with block on right. returnStep 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