Compile the memory allocator using the following command:
gcc -o memalloc.so -fPIC -shared -Wno-deprecated-declarations memalloc.c
Compile the memory allocator with the stress test:
gcc -o stress_test stress_test.c malloc.c -pthread
Assuming you are using a Unix-type operating system, follow these steps to use the custom memory allocator when running commands:
export LD_PRELOAD=$PWD/memalloc.so
This sets the LD_PRELOAD
environment variable to the path of the compiled memalloc.so
shared library.
To stop using the custom memory allocator, simply run:
unset LD_PRELOAD
This unsets the LD_PRELOAD
environment variable, reverting to the default memory allocation behavior.