Any tool to find size of memory allocated dynamically using malloc/realloc?

后端 未结 4 1787
时光说笑
时光说笑 2021-01-23 19:44

I have a MS-Visual Studio 2005 workspace having all c code. This application(exe) allocates memory dynamically from heap using malloc and realloc. I want to calculate the maximu

4条回答
  •  旧时难觅i
    2021-01-23 20:33

    If you statically link with the CRT, you can 'overrule' the implementation of malloc, realloc, free (in fact, all functions that appear in malloc.c, realloc,c free.c and/or dbgheap.c in the CRT). It is doable but may require some iterations before you get the full set of functions that need to be overruled.

    If you dynamically link with the CRT, you can redefine malloc, realloc and free like this:

    #define malloc(s)    mymalloc(s)
    #define realloc(p,s) myrealloc(p,s)
    #define free(p)      myfree(p)
    

    The implementations of mymalloc, myrealloc and myfree can then simply use malloc, realloc and free (be sure not to use the #define in the source file that implements mymalloc, ...) or you could use the native Windows functions.

提交回复
热议问题