Override new operator in C++ while crtdbg.h is causing conflicts

后端 未结 4 448
独厮守ぢ
独厮守ぢ 2021-02-02 04:48

While trying out some memory tracking and preparation for my own memory manager, I tried to override the new operator. The article on flipcode was my main guideline in this proc

4条回答
  •  情深已故
    2021-02-02 04:55

    On Visual Studio 2010, I was able to do this without redefinition of new or custom defined new. I created a header file with the following:

    #pragma once
    //_CRTDBG_MAP_ALLOC
    //_CRTDBG_MAP_ALLOC_NEW
    #define _CRTDBG_MAP_ALLOC
    #define _CRTDBG_MAP_ALLOC_NEW
    #include 
    #include 
    

    and forced its inclusion on every source file, with the already discussed option Forced Include File, in the Project Settings / Configuration Properties / C/C++ / Advanced. Actually, crtdbg.h already do this custom definition of new, along with undefinition of regular new. And just to make sure everything would run smoothy, I added _CRTDBG_MAP_ALLOC and_CRTDBG_MAP_ALLOC_NEW to Preprocessor Definition list, available in: Project Settings / Configuration Properties / C/C++ / Preprocessor.

    Hope this will help on this issue.

提交回复
热议问题