Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/150.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ _CrtMem*和调试堆_C++_Debugging_Memory Leaks - Fatal编程技术网

C++ _CrtMem*和调试堆

C++ _CrtMem*和调试堆,c++,debugging,memory-leaks,C++,Debugging,Memory Leaks,当我使用以下代码时,它会检测到内存泄漏。我怎么能做到不呢 _CrtMemState startState; _CrtMemState endState; _CrtMemState temp; _CrtMemCheckpoint(&startState); const char* foo = "I'm not leaking memory! Stop saying I am!"; _CrtMemCheckpoint(&endState); _CrtMemDifference(&

当我使用以下代码时,它会检测到内存泄漏。我怎么能做到不呢

_CrtMemState startState;
_CrtMemState endState;
_CrtMemState temp;

_CrtMemCheckpoint(&startState);
const char* foo = "I'm not leaking memory! Stop saying I am!";
_CrtMemCheckpoint(&endState);

_CrtMemDifference(&temp, &startState, &endState);    // Returns true. Wtf?

我剪切并粘贴了您的代码,并在VS2008下的我的机器上进行了测试,_CrtMemDifference返回0

常言道:“在我的机器上工作”;)


编辑:你有多个线程在运行吗?是否有可能另一个线程在2个CrtMemCheckpoint调用之间分配了一些内容

我剪切并粘贴了您的代码,并在VS2008下的我的机器上进行了测试,_CrtMemDifference返回0

常言道:“在我的机器上工作”;)


编辑:你有多个线程在运行吗?是否有可能另一个线程在2个CrtMemCheckpoint调用之间分配了一些内容

如果代码更改为const char[]No repro,即使调用了_crtsetdbgfagflag(),它是否检测到泄漏。我没想到会有。如果代码更改为const char[]No repro,即使调用了_crtsetdbgfagflag(),它是否检测到泄漏。我没想到会这样。没关系,是我的错。无关代码。谢谢你的快速回复。没关系,是我的错。无关代码。谢谢你的快速回复。