You could use it like you would other (1) replacement (2) malloc()
subsystems.
In the first example, malloc()
is generally replaced via:
#define malloc(n) GC_malloc(n)
#define calloc(m,n) GC_malloc((m)*(n))
...
#define free(n) GC_free(n)
You then link against the new malloc() library (statically or dynamically).
In the second example, LD_PRELOAD
is used to intercept calls to malloc()
/ free()
.
What I recommend you do is the first option, create a static / shared object called bsdmalloc
and link against it as desired.
You also have the option of just building the BSD malloc routines with your code, just like you would any other module (crude example including only stdlib where malloc is prototyped) :
#include <stdlib.h>
#define malloc(n) BSD_malloc(n)
void *BSD_malloc(int n)
{
return NULL;
}
int main(void)
{
char *ret;
ret = (char *) malloc(1024);
return ret == NULL ? 1 : 0;
}
For a more system wide approach, I really recommend going the shared object route.