tralloc

A C library that adds size information to memory allocations.
git clone git://src.gearsix.net/tralloc
Log | Files | Refs | Atom | README

tralloc.h (773B)


      1 /* See README.md for documentation
      2  *
      3  * IMPORTANT: Any `ptr` value used *must* be allocated by
      4  * tralloc or you'll run into problems.
      5  */
      6 
      7 #ifndef TRALLOC
      8 #define TRALLOC
      9 
     10 #include <stdlib.h>
     11 #include <assert.h>
     12 
     13 /* num. bytes heap-allocated by tralloc */
     14 size_t tr_siz();
     15 
     16 /* the max. number of heap-allocated bytes tralloc will allow */
     17 size_t tr_limit();
     18 
     19 /* set the max. number of heap-allocated bytes tralloc will allow, 0 = infinite */
     20 size_t tr_setlimit(size_t n);
     21 
     22 /* The number of bytes allocated for `ptr` */
     23 size_t tr_allocsiz(void *ptr); 
     24 
     25 /* stdlib wrappers
     26  * These behave the same as their stdlib counterparts */
     27 void *tr_malloc(size_t n);
     28 
     29 void *tr_calloc(size_t num, size_t n);
     30 
     31 void *tr_realloc(void *ptr, size_t n); 
     32 
     33 void tr_free(void *ptr); 
     34 
     35 #endif