I’m currently recoding the C/C++ malloc
function for Linux usage only. One of the challenges of that exercise is to make my function as close to the original malloc
as possible.
I usually use Valgrind to check if my mallocs are correctly allowed and freed, but I don’t know if Valgrind can pick other form of memory allocation, and if so, which ones?
Second question: assuming Valgrind doesn’t pick other forms of memory allocation, what else could I use to check if my function is working as intended?
Advertisement
Answer
Valgrind assumes malloc
to work as expected in order to manage memory allocation. If your goal is to make your own malloc
implementation, you cannot use Valgrind to debug it.
This is one of the challenge of this exercise: you have to debug it yourself.
If you want to check if your function works as intended, code a function show_alloc_mem
that dumps your memory and check if everything is displayed as you intended.