1.6 KiB
1.6 KiB
🧠 Memory Management Analyzer
This project demonstrates how different memory allocation methods (malloc, calloc, and mmap) perform in terms of speed and memory usage in a simulated workload.
📜 Description
The program dynamically allocates and frees memory blocks of varying sizes, measuring:
- Allocation and deallocation times.
- Memory usage via
/proc/self/statusor/proc/self/statm. - Peak memory consumption during execution.
It produces a report comparing performance across allocation methods.
🚀 Features
- Dynamic Allocation Testing – compares
malloc,calloc, andmmap. - Performance Metrics – measures allocation/deallocation times.
- Memory Usage Tracking – monitors real-time process memory usage.
- Optional Memory Leak Simulation – detects unfreed memory using Valgrind.
- CLI Mode Selection – choose allocator at runtime (
--malloc,--calloc,--mmap).
🛠️ Build
make
▶️ Run
./mem_analyzer --malloc
./mem_analyzer --calloc
./mem_analyzer --mmap
🧪 Test & Debug
make valgrind
📊 Example Output
Allocator: malloc
Blocks: 10000
Average Allocation Time: 0.24 μs
Average Free Time: 0.18 μs
Peak Memory Usage: 2.5 MB
📂 Project Structure
mem_analyzer/
├── README.md
├── Makefile
└── main.c
🔍 Learning Objectives
- Understand differences between
malloc,calloc, andmmap. - Learn to measure memory usage through
/proc. - Practice debugging memory errors with Valgrind.
- Gain insight into memory allocation strategies in Linux.