Skip to main content

Analyze and simulate dynamic memory usage in C/C++ code

Project description

memscope

🔍 Analyze and visualize memory allocation and release operations in C/C++ code.

🚀 Features

  • Detects malloc, calloc, realloc, new, delete, free
  • Counts allocation vs. deallocation operations
  • Detects potential memory leaks
  • Visualizes heap behavior over time using Matplotlib

📦 Installation

bash pip install memscope

Or from source: git clone https://github.com/MiriKanner/memscope cd memscope pip install -e

🧠 Quick Start

Analyze C/C++ Source Code

from memscope import analyze_source

result = analyze_source("examples/sample.c") print(result)

example output:

{ "allocs": 2, "frees": 1, "unfreed_allocations": 1, "lines": { "alloc": [4, 7], "free": [9] } }

Visualize Memory Operations

from memscope.visualizer import plot_memory_timeline, plot_memory_bars

events = [ {"step": 1, "allocated": 128, "freed": 0}, {"step": 2, "allocated": 256, "freed": 64}, {"step": 3, "allocated": 0, "freed": 320}, ]

plot_memory_timeline(events) plot_memory_bars(events)

🧩 API Reference

analyze_source(filepath: str) -> dict

Analyze a C/C++ source file and detect allocation/deallocation operations.

Parameters

---filepath: path to .c or .cpp file.

Returns: { "allocs": int, "frees": int, "unfreed_allocations": int, "lines": {"alloc": list[int], "free": list[int]} }

plot_memory_timeline(events: list[dict])

Plots total heap size over time.

plot_memory_timeline([ {"step": 1, "allocated": 128, "freed": 0}, {"step": 2, "allocated": 0, "freed": 128}, ])

plot_memory_bars(events: list[dict])

Plots allocation (green) and free (red) deltas.

plot_memory_bars([ {"step": 1, "allocated": 200, "freed": 0}, {"step": 2, "allocated": 0, "freed": 100}, ])

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

memscope-0.1.2.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

memscope-0.1.2-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file memscope-0.1.2.tar.gz.

File metadata

  • Download URL: memscope-0.1.2.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for memscope-0.1.2.tar.gz
Algorithm Hash digest
SHA256 9cf094d62c855cbd4f08367be2842d51808c875981e65c695cc1125db805e58a
MD5 258740bc191309fd05d1c29ea8728a9c
BLAKE2b-256 83589a000db28b84e771f0a6c94ff5dfa7f0fb26dc80000d8c0f2d41e1c1195c

See more details on using hashes here.

File details

Details for the file memscope-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: memscope-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for memscope-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a6d7b2cfd83d422b8905a91f169634c07c0127d86795f7f8b30ed3053e543bf2
MD5 79035a190cd7f8c3434725fb807201cc
BLAKE2b-256 781e30bb3a8b4a77fde63d293e4f4e1c8499034fbf04b31eebfe20643cd4636b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page