This is a live memory visualiser written in C for Windows. It tracks allocations and deallocations in a simulated heap, logs the memory state to a JSON file, and visualises it in real-time using an animated HTML page.
- Continuous memory tracking:
- Allocations and deallocations are logged to memory_log.json every 0.5 seconds.
- Interactive memory simulation:
- Press 'a' to allocate a 32B block.
- Press 'f' to free the last unfreed block.
- Press 'q' to quit the programme.
- Animated HTML visualisation:
- Uses CSS and JavaScript to display blocks with height proportional to size.
- Green blocks = allocated, Red blocks = freed.
- Safe memory cleanup:
- All memory is freed when the programme exits.
- Optional automatic mode:
- The programme can be configured to randomly allocate/free blocks for demonstration.
- Unlimited allocations can consume large amounts of memory. Avoid pressing 'a' excessively.
- File writing occurs every 0.5 seconds to memory_log.json. Ensure the file is not locked by another programme.
- If the programme is terminated abruptly, memory is released by Windows but JSON may not be fully updated.
- Designed for Windows; does not use POSIX sockets.
- Windows OS
- GCC (e.g., via MinGW) for compilation
- Python 3 (for running a local HTTP server to view HTML)
- Web browser (Chrome, Edge, Firefox, etc.)
- Memory_Visualiser_LoggerV2.c - C programme to simulate memory allocations/frees and log to JSON.
- Mem_VisualiserV2.html - HTML + JS file for animated visualisation.
- Memory_Visualiser_V2.exe - Compiled Windows executable (optional; source code recommended).
- memory_log.json - JSON file generated by the C programme.
- README.txt - this file.
Open PowerShell or Command Prompt in the folder containing the files:
gcc Memory_Visualiser_LoggerV2.c -o Memory_Visualiser_V2.exe
.\Memory_Visualiser_V2.exe
- The programme will run indefinitely.
- Use keys:
- 'a' → allocate 32B memory block
- 'f' → free the last unfreed block
- 'q' → quit the programme
Open another terminal in the same folder and run:
python3 -m http.server 8000
This will serve the folder at http://localhost:8000
Open your web browser and navigate to:
http://localhost:8000/Mem_VisualiserV2.html
- The page will fetch memory_log.json every second.
- Blocks will animate as memory is allocated or freed.
You can modify Memory_Visualiser_LoggerV2.c to randomly allocate/free blocks in a loop instead of manual keypresses. This will simulate heap activity automatically and continuously.
- The JSON file is overwritten on every update.
- The HTML visualisation can be refreshed manually or will update automatically if polling is enabled.
- Scaling factor in the HTML file may be adjusted for better visibility of block heights.
This is provided for educational purposes. Use at your own risk.