The inspiration for this project was my Operating Systems class at BBU, Babeș-Bolyai University, during which, I got my hands on the Standard Library Memory Allocator. Using the knowledge obtained then, I created my humble version of the memory allocator, which thrives not in efficiency, but in being my very own shot at it. However, a great source of inspiration was this article.
To build the project, run the build.sh
script:
./build.sh
Include the malloc.h
header in your C program:
#include "malloc.h"
void *my_malloc(size_t nsize)
- allocates a block of memory of the specified sizevoid my_free(void *block)
- frees a previously allocated block of memoryvoid *my_calloc(size_t num, size_t nsize)
- allocates memory for an array of elements and initializes them to zerovoid *my_realloc(void *block, size_t nsize)
- changes the size of a previously allocated memory block
- Concurrency - in order to avoid race conditions (different processes read and write the same memory blocks simultaneously), I used
pthread_mutex_lock
, that ensures mutual exclusivity for one process to the memory block. - Memory Acquisition - my implementation uses the system call
void *sbrk(int incr)
to increase or decrease the program's data segment size and therefore, request more memory from the operating system. - Memory Representation - the allocator maintains a singly linked list of all memory blocks, both allocated and free.