Memory Allocator (ITI8510)
Mall:Itv8510 This task will be part of the final grading.
Task
Write your own memory allocator which could replace malloc()/free() pair. There are a few requirements:
- Allocator should re-use freed memory.
- It should not crash.
Write two functions:
void * Malloc(size_t size) void Free(void * ptr)
Questions
- How should I allocate the memory for allocator?
Since the program should handle its memory all by itself, you should use sbrk() function to move the heap pointer (the same thing what malloc does internally). Do not free the memory using sbrk(), just mark it for re-use.
- What algorithm should I use?
Use either first-fit or best fit algorithm. Joining of nearby blocks is highly reccommended. Memory segregation is not needed (you do not have to create classes for larger and smaller allocations).