This is a custom memory manager I wrote in C++ for COP4600 at the University of Florida. It requests a block of memory from the operating system with mmap and handles allocations inside that block.
- Allocates and frees word-aligned memory
- Tracks free and allocated blocks with a doubly linked list
- Splits larger holes when only part of the space is needed
- Merges neighboring holes after memory is freed
- Supports best-fit and worst-fit allocation
- Returns the current memory layout as a list or bitmap
- Writes the current hole list to a text file using POSIX calls
- Builds as a static library
The manager starts with one free block covering the entire memory region. When memory is requested, the selected allocation function searches the list of available holes and returns an offset. The manager then marks that space as used and creates a smaller free block if there is leftover space. When a block is freed, the manager checks the blocks before and after it. Any neighboring free blocks are combined to reduce fragmentation.
in order to use this the project requires Linux, a C++17 compiler, and GNU Make.
makeThis creates libMemoryManager.a.
Then to link it with another program:
g++ -std=c++17 program.cpp -L. -lMemoryManager -o program#include "MemoryManager.h"
int main() {
MemoryManager manager(8, bestFit);
manager.initialize(1024);
void* block = manager.allocate(64);
manager.free(block);
manager.shutdown();
return 0;
}MemoryManager.hcontains the class and function declarations.MemoryManager.cppcontains the memory manager and allocation algorithms.Makefilebuilds the static library.