This is a simple library to implement the functionality of malloc
using mmap
. This project is meant to be a learning process.
The header file mem_lib.h
contains all of the function prototypes for the library.
The main functions to implement in this library are:
-
HEAP_ALLOC(size_t req)
: Allocates a block of memory of the requested size. -
HEAP_FREE(void *ptr)
: Frees the previously allocated memory block pointed to byptr
. -
HEAP_REALLOC(void *ptr, size_t resize)
: Resizes a previously allocated memory block. -
HEAP_GROW()
: Grows the heap if original is out of space -
HEAP_CALLOC(size_t nelem, size_t elsize)
: Allocate unused space of n elements of size n
To run the program, follow these steps:
-
Clone the repository:
git clone https://github.com/kam-stand/KH_MALLOC.git
-
Change into the root directory:
cd SIMPLE_MALLOC
-
Make the
run.sh
script executable:chmod +x run.sh
-
Run the script:
./run.sh
There is a folder called ./ARENA_ALLOCATOR
that is used as inspiration and sometimes serves as base-level logic to implement certain functions like merge
and free
in a much more simplified manner.
It might also contain useful links to help either implement your own version of a memory allocator
- This is a project for me to better understand memory allocation
- There is possibly memory leaks as it may have ineffeciency and holes somewhere in the logic