thistle-sdk
Thistle SDK documentation
Loading...
Searching...
No Matches
malloc.c

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)
int main() {
int *p = malloc(4);
if (p == NULL) {
printf("Failed to allocate memory\n");
return 1;
}
*p = 42;
printf("%d\n", *p);
free(p);
return 0;
}
#define malloc(size)
Definition: malloc.c:16
#define free(ptr)
Definition: malloc.c:17
int main()
Definition: malloc.c:19