This C program simulates operating system memory allocation strategies including Contiguous Allocation, Paging, and shows Fragmentation Analysis through a colorful and interactive terminal interface.
- β 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
- Total Memory:
1024 blocks - Page Size:
8 blocks - Each block is visualized as a single unit in the terminal.
Each memory block stores:
start: start indexsize: block size (default 1)allocated: whether the block is usedprocess_id: PID of the processis_page: true if it's part of a pagepage_number: number within process
-
Demo Mode
- Demonstrates multiple memory operations step-by-step.
-
Interactive Mode
- Choose from a menu to allocate/free memory, inspect blocks, or reset.
=== 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: Shows total free blocks and largest contiguous free block.
- C compiler (e.g., GCC)
- Terminal (supports ANSI color codes)
Open a terminal in the src directory and run:
gcc *.c -o memory_visualizer
./memory_visualizerOn Windows, run:
memory_visualizer.exememory_allocator_project/
β
βββ include/
β βββ allocator.h
β βββ common.h
β βββ fragmentation.h
β βββ visualizer.h
β
βββ src/
β βββ allocator.c
β βββ fragmentation.c
β βββ main.c
β βββ visualizer.c
β
βββ README.md
Developed for educational purposes to demonstrate memory allocation strategies