Question: n this assignment we re going to experiment with dynamic memory as well as explore some of the properties of different memory approaches. Phonebook Variants
n this assignment were going to experiment with dynamic memory as well as explore some
of the properties of different memory approaches.
Phonebook Variants
We are going to create variants of our phonebook program from assignment If you are
unsure of your solution you can use the provided solution as long as you include a comment
citing what functions were used and what changes you needed to make.
All of these variants focus on a specific deficiency that our phonebook has, that is that its
size is limited and fixed. Dynamic allocation gives us some tools to solve that.
You should read all three variants and consider if there are any changes to the base imple
mentation that will make these modifications easier. hint: creating a function to get a free
node is probably going to be very helpful
Once you have a base implementation you should rename it phonebookbase.c and create
a makefile rule phonebookbase to build this base version. It is a good idea to also
develop a set of tests which you can use to validate that all further variants work as intended.
Allocation and Expansion Points
Copy your phonebookbase.c to phonebookmallocblock.c and create a makefile rule
which can build this variant.
In this variant we will change our fixed node array to one that is malloced or calloced
when the list is initialized. The free list will be populated from this allocation.
When the free list runs out of nodes, it should be expanded by malloc This can happen
either when the last node is used, or when the next node is created. Document your choice
in the infile comments.
Your malloccalloc blocks should be of a size PHONEBOOK SIZE which should be set
to
Ensure you test your solutions ability to expand the list.
Ondemand Allocation Points
Copy your phonebookbase.c to phonebookmalloc.c and create a makefile rule which can
build this variant.
In this variant we will remove our fixed node array and the free list will be unused. Instead,
each time a node is requested it should be allocated with malloccalloc
When a node is removed from the list, it should be freeed Phonebook clear should free
all used nodes.
Ensure this solution is able to add and remove items from the list. hint use valgrind to
ensure that memory is not corrupted or leaked
BONUS Points
Some of you may have noticed that the Allocation and Expansion approach currently leaks
memory. To receive full marks for the bonus develop a method to ensure that all the memory
chunks are freed when the list is cleared.
BONUS BONUS Points
Extend this freeing behaviour to freeing chunks when they are no longer used ie all there
memory is on the free list Consider the performance implications of your approach.
Note, that attempting the bonus without having a solid implementation of the base prob
lem may result in you base solution not working and the loss of marks in that section.
ATTEMPTING the bonus will not be considered a reason for nonbonus functionality not
working.
Evaluating the Variants Points
Using your profiler from LE develop several additional test inputs which you believe will
be interesting for exploring these variants including the base For example, the list in the
Allocation and Expansion variant is growing every nodes, so measuring over multiple of
boundaries will likely be interesting.
The number of tests inputs needed is up to you, it should be enough you can develop an
understanding of the impact and tradeoffs of each approach. Your test inputs should work
on all variants you may need to make slight fixes to their code to achieve this
Based on your testing write a short report on the approaches, your report should identify
the following for each: The general behaviour of memory, cpu, and duration; usages of this
approach ie scenerios where is performs better, or performs better in some way; usages
to avoid ie scenerios where this approach performs poorly or poor in some way Your
descriptions should identify the specific data you collected that supports your statements.
Consider if there are modifications to the exact approaches described here that would be
interesting to explore and what you hypothesize they would change in your results.
In your conclusion, propose a method you would use to select between these approaches.
You may format this report in any of markdownpdf or plain text but no other docu
ment types.
Files to hand in
All source files must be on git. The following files are to be packaged into a tarball atar
and submitted to canvas:
git.log
Makefile
phonebookbase.c
phonebookmallocblock.c
phonebookmalloc.c
analaysis.md pdf txt
You can generate the git.log file with the following command:
git log main..a git.log
Your tarball should be flat contain no subdirectories and should not contain any files not
listed above. Remember the com
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
