A quick example of how to use the mallocng library.
Usage should be quite straight forward considering the compatibility with the standard C library.
Build with the following command, taking the .a
file for your target platform
$ cc -o malloc malloc.c libmallocng.a
#include <stdio.h>
#include <malloc.h>
#include "../target/mallocng.h"
#define malloc(size) tma_malloc(size)
#define free(ptr) tma_free(ptr)
if (p == NULL) {
printf("Failed to allocate memory\n");
return 1;
}
*p = 42;
printf("%d\n", *p);
return 0;
}
#define malloc(size)
Definition: malloc.c:16
#define free(ptr)
Definition: malloc.c:17
int main()
Definition: malloc.c:19