An Algo Project at Codam (42). This project is about implementing a dynamic memory allocation mechanism.
This mini project is about writing a dynamic allocation memory management library. Complete Subject
Use Evaluation sheet or Test
Functions allowed for use:
mmap(2)
munmap(2)
getpagesize(3)
getrlimit(2)
write(2)
Project must be written according to the 42 coding standards, the Norme.
Rewrite the following functions:
void free(void *ptr);
void *malloc(size_t size);
void *realloc(void *ptr, size_t size);
- allocations must belong to 3 different memory areas depending on allocation size (
TINY,SMALL,LARGE) TINYandSMALLareas must be preallocated and must have enough space for at least 100 allocations
Write the following function:
void show_alloc_mem();
It's output must be formatted as follows:
TINY : 0xA0000
0xA0020 - 0xA004A : 42 bytes
0xA006A - 0xA00BE : 84 bytes
SMALL : 0xAD000
0xAD020 - 0xADEAD : 3725 bytes
LARGE : 0xB0000
0xB0020 - 0xBBEEF : 48847 bytes
Total : 52698 bytes
Extra functionality:
- "defragment” the freed memory
void show_alloc_mem_ex(int mode);- function that displays more details depending onmodepassed as argument:SHRT- short mode, the same output as forshow_alloc_memSTD- standard mode, outputs block metadataEXT- extended mode, outputs hex dump of memory stored in thedataarea of the block
- clone repository
- if you don't have
norminetteinstalled on your device, comment out lines 29-36 in the filetest/test.sh
cd test
sh test.sh