GithubHelp home page GithubHelp logo

dmt's Introduction

Dynamic Memory Tracker (DMT) Library

Description

A small C library for detecting memory leaks, tracking memory usage and detecting invalid frees or reallocs. The library consists of two files (dmt.c and dmt.h) and provides wrappers for the 4 main dynamic memory functions in C (malloc, calloc, realloc and free). The library is currently thread unsafe.

Usage

The library should be dropped inside a C project and compiled along with it. The library provides the following macros and functions:

  • void* dmt_malloc(size_t size) A wrapper for malloc
  • void* dmt_calloc(size_t num, size_t size) A wrapper for calloc
  • void* dmt_realloc(void* ptr, size_t size) A wrapper for realloc
  • void dmt_free(void *ptr) A wrapper for free
  • size_t dmt_size(void* ptr) Returns the size in bytes of a pointer's allocation
  • void dmt_dump(FILE* fp) Dumps information about the currently unfreed allocations
  • size_t dmt_usage(void) Returns the total number of bytes currently allocated
  • int dmt_has(void* ptr) Returns non-zero if the pointer is allocated by dmt

The wrapper macros (dmt_malloc, dmt_calloc, dmt_realloc and dmt_free) should be used in place of the functions which they wrap (malloc, calloc, realloc and free). Their arguments and return values match those of the functions they wrap.

Additional options can be set by defining the following macros:

  • DMT_UNSAFE Avoids checking whether a pointer passed to dmt_free or dmt_realloc is valid -- this may offer a noticable speed increase in programs with many allocations
  • DMT_ABORT_NULL If malloc, calloc or realloc return with NULL, the program will abort with an error
  • DMT_STACK_TRACE (Linux only) When using dmt_dump each unfreed allocation is also accompanied with a stack trace from when the allocation was made. Additionally, if the program aborts with an error it will dump a stack trace to stderr

License

This library is free software; you can redistribute it and/or modify it under the terms of the MIT license. See LICENSE for details.

dmt's People

Contributors

rxi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.