tralloc

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

commit ec743e370d6ad71463930e5e744d0e54f80ebb97
parent 0a930b465cf2e90229135b2be22573a4997fc6f4
Author: gearsix <gearsix@tuta.io>
Date:   Mon,  6 Sep 2021 22:17:36 +0100

added some inline doc

Diffstat:
Mstdlibw.c | 5+++++
Mstdlibw.h | 20+++++++++++++++-----
2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/stdlibw.c b/stdlibw.c @@ -1,5 +1,10 @@ #include "stdlibw.h" +/** _heap + * main function for tracking allocated heap memory using a + * `static size_t`. Only tracked memory allocated with other + * _stdlibw_ functions +**/ static size_t _heap(char op, size_t n) { static size_t siz = 0, lim = 0; diff --git a/stdlibw.h b/stdlibw.h @@ -22,23 +22,33 @@ size_t heaplim(); size_t limheap(size_t n); /** - * sizeofw - sizeof wrapper + * sizeofw - sizeof (wrapper) * returns the number of allocated bytes for `ptr`. * will fail if called on a pointer not allocated by stdlibw. **/ size_t sizeofw(void *ptr); -/** mallocw - malloc wrapper - * malloc (sizeof(size_t) + siz) bytes and return that pointer from [1] - * [0] is used to store `siz`. - * `(siz + sizeof(size_t))` will be added to `heapsiz` +/** mallocw - malloc (wrapper) + * malloc (sizeof(size_t) + siz) bytes and return [1] of that pointer. + * [0] is used to store `siz` for other stdlibw operations. + * `(siz + sizeof(size_t))` will be added to tracked `heapsiz`. **/ void *mallocw(size_t siz); +/** callocw - calloc (wrapper) + * see `mallocw()`. Duplicate, but for `calloc`. +**/ void *callocw(size_t num, size_t siz); +/** reallocw - realloc (wrapper) + * `mallocw()` a new pointer, copy `ptr` contents to it and `freew()` + * ptr. +**/ void *reallocw(void *ptr, size_t siz); +/** freew - free (wrapper) + * free a pointer allocated by a *stdlibw* alloc function. +**/ void freew(void *ptr); #endif