clempaul.me.uk » BlogGallerySoftware

Overriding C Memory Functions

Sometimes it is necessary to override C's memory functions, for instance to count how much memory is being allocated/freed.

To do this, simply use code similar to the following:

void *myMalloc(size_t size) {
	//logging action
	
	return malloc(size);
}

void *myFree(void *ptr) {
	// logging action
	
	return free(ptr);
}

#define malloc(size) myMalloc(size)
#define free(ptr) myFree(ptr)