This assignment is not difficult (they never are), but there are a lot of things going on here. If you want things to go smoothly, I highly recommend that you create a makefile for this project. There are several files that need to be built, and if you insist on doing it the hard way, one-at-a-time by-hand, you will most certainly get confused. The 10 minutes or so that you spend creating the makefile will pay-off in a very short time.
gcc -O -g -Wall -Wextra -Werror -ansi -pedantic driver-sample-s.c memmgr.c -o memmgr
where X is the test number to run and Y is the value for the policy used to find an available block of memory. A value of 0 means first-fit and a value of 1 (or any non-zero value) means best-fit. The default is to run all tests using the first-fit policy. This flag only applies to the last 4 tests. See the driver for details../memmgr X Y
To detect memory errors and leaks, run it under valgrind like this:
replace X with the test number to run and Y with the policy.valgrind -q --leak-check=full --show-reachable=yes --tool=memcheck ./memmgr X Y
For example, assume you have the graph definition in a text file named graph.txt and you want to create a PNG file called graph.png. This is the command:dot -T graphic-type -o output-file input-file
dot -T png -o graph.png graph.txt
Shared LibraryNo changes to your memmgr.c file are required, but the way you build it is a little different:
gcc -O -g -Wall -Wextra -Werror -ansi -pedantic -fPIC -c memmgr.c -o memmgr.o gcc -shared memmgr.o -o libmemmgr.so
gcc -O -g -Wall -Wextra -Werror -ansi -pedantic -c shared.c -o shared.o
A note about the dlsym library function: Because the dlsym function can return NULL as a valid value of a requested symbol, it is not always safe to assume that a NULL value being returned is an indication of an error. However, for our purposes (and with the way we're implementing things), a NULL value will indicate an error condition. So, if the return from dlsym is NULL, you will return FAILURE immediately. (DO NOT call dlerror as that will mess things up when the driver calls it.)
gcc -O -g -Wall -Wextra -ansi -pedantic -Werror driver-sample-d.c shared.o -o memmgr-d -ldl
Be aware that I will be running/grading your assignment based on the shared object version. The static version above was just for you to get a working memory manager. So, if you got the static version working, but not the shared object version, you will receive a failing grade for the assignment.
You need to capture your shell session that shows various things like compiling and running the program, using diff to make sure your output is correct and running with valgrind and then running Doxygen. After you've finished coding and testing everything and are sure everything is correct, use the script command to make a text file of your session. From the bash shell in the directory you've setup to test with, run these commands: (You'll need a proper Doxygen config file called Doxyfile for the doxygen command to work.)
Then, press Ctrl-D to end the script session. A file named typescript was created with all of the commands and output. Replace FIRSTNAME and LASTNAME with your real first name and last name. This is how you get your name in the typescript file. Consult the man pages if you want more information on script.script date uptime echo FIRSTNAME LASTNAME pwd whoami uname -a cat /proc/cpuinfo cat /proc/meminfo gcc -O -g -Wall -Wextra -Werror -ansi -pedantic -fPIC -c memmgr.c -o memmgr.o gcc -shared memmgr.o -o libmemmgr.so gcc -O -g -Wall -Wextra -Werror -ansi -pedantic -c shared.c -o shared.o gcc -O -g -Wall -Wextra -ansi -pedantic -Werror driver-sample-d.c shared.o -o memmgr-d -ldl ./memmgr-d 2 0 | tee output.txt diff --strip-trailing-cr output.txt output-alloc2.txt valgrind -q --leak-check=full --show-reachable=yes --tool=memcheck ./memmgr > /dev/null doxygen ls -al html/