The purpose of lab today is to get you familiar with how to debug malloc/free in valgrind.
We’re going to get started writing code to help with homework 7 today. If you’ve already written code for this, start there. Otherwise, create a new c file called scheduler.c.
Create a struct to represent a person at the university and call it Person. People all have the following attributes (you’re free to name these in your underlying data structure whatever you want as long as your names are appropriately descriptive):
In tandem with this, make the following creation function:
This method will create a Person struct, allocate space for them on the heap, instantiate all the fields in the struct, and then return a pointer on the heap.
Similarly to gdb, in order to debug your code with valgrind, you need to use the -g flag.
valgrind --tool=memcheck will check the memory. The HEAP SUMMARY shouldn’t show anything in use at exit.
There are many other options to use. Some demoed in lecture valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes. Others are listed in the manual: http://valgrind.org/docs/manual/mc-manual.html.
Points will be allocated as follows
It’s ok not to finish this assignment – get through as much as you can.
Zip up your scheduler.c file into a zip file entitled yourCSUsername.zip. Then drop the zip file into the dropbox under the lab-08 folder..