Is there a way to redefine malloc at link time on Windows?

前端 未结 4 983
我在风中等你
我在风中等你 2020-12-23 23:34

I would like to replace the default malloc at link time to use a custom malloc. But when I try to redefine malloc in my program, I get this error:

MSVCRT.lib         


        
4条回答
  •  孤独总比滥情好
    2020-12-24 00:06

    What about defining malloc=_custom_malloc in the project makefile. Than adding a file such as:

    my_memory.c
    #undef malloc
    #undef calloc
    ...
    void *_custom_malloc(int size) { return jmalloc(size); }
    void *_custom_calloc(int size) { return jcalloc(size); }
    ...
    

提交回复
热议问题