Skip to content

This project includes a custom implementation of malloc and its associated functions (free, calloc, realloc) in C, using the sbrk system call to reduce overhead. The allocator preemptively allocates additional memory and uses metadata to manage space efficiently. Cam be tested using the LD_PRELOAD trick on UNIX (and POSIX-compliant systems).

Notifications You must be signed in to change notification settings

dcruzeneil/custom-memory-allocator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Custom Implementation of malloc and Associated Functions (free, calloc, realloc) in C

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.

Building the Shared Library

To create the shared library, use the provided Makefile:

make

This will generate the my-malloc.so shared library.

Testing this Custom malloc

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]
Example

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.

About

This project includes a custom implementation of malloc and its associated functions (free, calloc, realloc) in C, using the sbrk system call to reduce overhead. The allocator preemptively allocates additional memory and uses metadata to manage space efficiently. Cam be tested using the LD_PRELOAD trick on UNIX (and POSIX-compliant systems).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors