gpt4 book ai didi

c++ - _CrtMem* 和调试堆

转载 作者:太空宇宙 更新时间:2023-11-04 12:26:37 24 4
gpt4 key购买 nike

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

_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 调用之间分配了一些东西?

关于c++ - _CrtMem* 和调试堆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2104598/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com