Skip to content

🧠 A C program that simulates operating system memory allocation strategies (contiguous allocation and paging), visualizes memory usage in the terminal πŸ“Š, and analyzes fragmentation with interactive πŸ•ΉοΈ and demo 🎬 modes.

Notifications You must be signed in to change notification settings

dpk45deepak/Memory-Visualizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 Memory Allocation Visualizer (C Project)

This C program simulates operating system memory allocation strategies including Contiguous Allocation, Paging, and shows Fragmentation Analysis through a colorful and interactive terminal interface.


🎯 Features

  • βœ… Contiguous memory allocation using First Fit
  • βœ… Paged memory allocation using fixed-size pages
  • βœ… Interactive and color-coded memory visualization
  • βœ… Detailed block-wise memory information
  • βœ… Calculation of fragmentation
  • βœ… Demo mode and Interactive mode
  • βœ… Terminal-compatible across Linux, macOS, Windows

πŸ“¦ Memory Configuration

  • Total Memory: 1024 blocks
  • Page Size: 8 blocks
  • Each block is visualized as a single unit in the terminal.

πŸ› οΈ How It Works

Memory Block Structure

Each memory block stores:

  • start: start index
  • size: block size (default 1)
  • allocated: whether the block is used
  • process_id: PID of the process
  • is_page: true if it's part of a page
  • page_number: number within process

Modes

  1. Demo Mode

    • Demonstrates multiple memory operations step-by-step.
  2. Interactive Mode

    • Choose from a menu to allocate/free memory, inspect blocks, or reset.

πŸ“Έ Visual Output Example

=== Memory ===
|_ |_ |_ |1 |1 |1 |1 |1 |1 |1 |1 |1 |2 |2 |2 |2 |2 |2 |2 |2 |_
...

Legend:

  • Numbers: Allocated process blocks
  • _: Free memory

πŸ” Fragmentation Analysis

  • Fragmentation: Shows total free blocks and largest contiguous free block.

πŸ“₯ How to Compile & Run

🧾 Requirements

  • C compiler (e.g., GCC)
  • Terminal (supports ANSI color codes)

πŸ’» Build and Run

Open a terminal in the src directory and run:

gcc *.c -o memory_visualizer
./memory_visualizer

On Windows, run:

memory_visualizer.exe

πŸ“ File Structure

memory_allocator_project/
β”‚
β”œβ”€β”€ include/
β”‚   β”œβ”€β”€ allocator.h
β”‚   β”œβ”€β”€ common.h
β”‚   β”œβ”€β”€ fragmentation.h
β”‚   └── visualizer.h
β”‚
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ allocator.c
β”‚   β”œβ”€β”€ fragmentation.c
β”‚   β”œβ”€β”€ main.c
β”‚   └── visualizer.c
β”‚
└── README.md

πŸ™Œ Credits

Developed for educational purposes to demonstrate memory allocation strategies

About

🧠 A C program that simulates operating system memory allocation strategies (contiguous allocation and paging), visualizes memory usage in the terminal πŸ“Š, and analyzes fragmentation with interactive πŸ•ΉοΈ and demo 🎬 modes.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published