This repository contains my implementation of the malloc() function in C. Please note that this is primarly made for fun and eductional purposes to understand how the heap works. It is by no means a one-to-one implementation.
- Dynamic Memory Allocation: The allocator dynamically manages memory using the
mmapsystem call. - Allocation and Deallocation: Users can allocate and deallocate memory using the
mem_allocandmem_freefunctions. - Chunk Management: The allocator maintains lists of allocated and free memory chunks.
-
Compile the Code: (uses
clangby default)$ make $ ./heap
-
Use the
mem_alloc()function to allocatoe memroy:void *ptr = mem_alloc(32);
-
Use the
mem_free()function to deallocate memory:mem_free(ptr1);
- Only works on systems that have the
mmap()system call - Not thread safe
- Max heap size of 4096 bytes