Skip to content

OS-Level Dynamic Memory Allocator Emulator in C. Simulates malloc/free using Doubly Linked Lists and First-Fit algorithm.

License

Notifications You must be signed in to change notification settings

mVefa/memory-manager-os

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧠 OS Memory Manager Emulator in C

Language Platform Data Structure License

📖 Overview

This project is a custom Dynamic Memory Allocator written in C. Developed for an Operating Systems course, it simulates the low-level behavior of standard malloc() and free() functions. The system manages a static memory pool using a Doubly Linked List to track allocated and free blocks.

It provides an interactive Command Line Interface (CLI) to allocate memory, free specific blocks, and visualize the real-time memory map.

✨ Key Features

  • ⚡ First-Fit Algorithm: Efficiently scans the memory pool to find the first block that is large enough to satisfy the allocation request.
  • ✂️ Block Splitting: Prevents internal fragmentation. If a free block is larger than requested, it automatically splits the block into two: one for the user data and one for the remaining free space.
  • 🔄 Automatic Coalescing: Eliminates external fragmentation. When memory is freed, the system checks adjacent blocks and merges them if they are also free, creating larger contiguous memory segments.
  • ⏱️ Performance Benchmarking: Uses POSIX clock_gettime() to measure and report allocation times in milliseconds, ensuring high-resolution performance tracking.
  • 🛡️ Memory Alignment Safe: Utilizes __attribute__((packed)) for metadata structs, preventing hardware alignment faults commonly found in embedded systems.

🧱 Architecture & Memory Map

The memory pool is divided into blocks. Each block consists of a Metadata Header (containing size, status, and list pointers) followed by the actual User Data.

Metadata (Block struct) User Data Metadata User Data ...
24 Bytes Variable Size 24 Bytes Variable Size ...

📸 CLI Interface

The system provides a clean terminal interface to interact with the memory pool.

Memory Map Output Allocation Tracking
`BLOCK 0: USED, Size: 1024 Address: 0x...<br>BLOCK 1: FREE, Size: 19432

🛠️ Tech Stack & Requirements

  • Language: C (C99 standard or higher)
  • Compiler: GCC
  • Build Tool: GNU Make
  • OS: POSIX compliant systems (Linux, macOS, Windows via WSL)

🚀 Installation & Usage

  1. Clone the Repository:
    git clone [https://github.com/mVefa/memory-manager-os.git](https://github.com/mVefa/memory-manager-os.git)
    cd memory-manager-os
  2. Compile the Project:
    make
  3. Run the Emulator:
    ./bellek_yoneticisi
  4. (Optional) Clean build files:
    make clean

🔮 Future Work (Roadmap)

  • Thread Safety: Implementing mutex locks to make the allocator thread-safe for multi-threaded applications.
  • Algorithm Switcher: Adding options to switch between First-Fit, Best-Fit, and Worst-Fit allocation strategies at runtime.
  • Memory Paging Simulation: Expanding the emulator to support virtual memory paging and page replacement algorithms (LRU, FIFO).

👨‍💻 Author

Muhammet Vefa Yoksul

  • Computer Engineering Student
  • Interests: Artificial Intelligence, Embedded Systems & Low-Level Programming.

Built with ❤️ for OS enthusiasts

About

OS-Level Dynamic Memory Allocator Emulator in C. Simulates malloc/free using Doubly Linked Lists and First-Fit algorithm.

Topics

Resources

License

Stars

Watchers

Forks