Play and learn 300 000+ tabs online

Friday, August 6, 2010

memory allocate free tracking

void *mmalloc(size_t size)
G_inUse += size;
return malloc(size);

void mfree(void *p)
size_t *sizePtr=((size_t *) p)-1;
G_inUse -= *sizePtr;

Here if we request 10 bytes of memory, malloc will allocate 11 byte(for ex: address is 2000 means 1999 will have size of the alloceated memory)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.