This project features a custom implementation of malloc and its associated functions (free, calloc, realloc) in C, built around the sbrk system call to reduce overhead. This custom memory allocator preemptively allocates more memory than requested and uses metadata structures to determine if additional system calls are necessary or if existing space can be used.
Note: This code is written for UNIX systems but should run on any POSIX-compliant machine.
To create the shared library, use the provided Makefile:
makeThis will generate the my-malloc.so shared library.
To test this implementation by overwriting the existing malloc definition used by all programs, use the LD_PRELOAD trick:
LD_PRELOAD=./my-malloc.so [COMMAND/PROGRAM TO RUN]To run VIM with this custom implementation of malloc (assuming the terminal is opened in the same directory as my-malloc.so):
LD_PRELOAD=./my-malloc.so vim Note: This custom implementation may cause VIM to run slower than usual.