Skip to content

About

custom c++ memory manager using mmap, linked-list tracking, and best-fit/worst-fit allocation

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

Memory Manager

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.

What it does

  • 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

How it works

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.

Build

in order to use this the project requires Linux, a C++17 compiler, and GNU Make.

make

This creates libMemoryManager.a.

Then to link it with another program:

g++ -std=c++17 program.cpp -L. -lMemoryManager -o program

for example:

#include "MemoryManager.h"

int main() {
    MemoryManager manager(8, bestFit);
    manager.initialize(1024);

    void* block = manager.allocate(64);
    manager.free(block);

    manager.shutdown();
    return 0;
}

Files for the project are below

  • MemoryManager.h contains the class and function declarations.
  • MemoryManager.cpp contains the memory manager and allocation algorithms.
  • Makefile builds the static library.

About

custom c++ memory manager using mmap, linked-list tracking, and best-fit/worst-fit allocation

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages