使用_CrtDumpMemoryLeaks显示数据来安慰 [英] using _CrtDumpMemoryLeaks to display data to console

查看:123
本文介绍了使用_CrtDumpMemoryLeaks显示数据来安慰的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的正常工作 _CrtDumpMemoryLeaks 功能
但文件中有承诺不仅要返回true或false也能打印一些信息。

I'm using _CrtDumpMemoryLeaks function which works fine but in the documentation there promised not only to return true or false but also to prints some information.

我试图用

_CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG );

但没有在这里出现在屏幕上我的一些code的。

but nothing appear on the screen here some of my code.

#define _CRTDBG_MAP_ALLOC 
#include <stdlib.h>
#include <crtdbg.h>   
#include <stdio.h>
#include <string.h>

int main() {
slist* students = 0;
clist* courses = 0;
char  c;
char  buf[100];
int   id, num;

malloc(100);
_CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG );


printf("there is memmory leaks?: %d\n",_CrtDumpMemoryLeaks());
system("pause");

return 0;
}

输出没有关于内存泄漏的数据..
这是为什么?

the output has no data about the memory leaks.. why is that?

顺便输出

有memmory泄漏?:1
preSS任意键继续。 。

there is memmory leaks?: 1 Press any key to continue . . .

推荐答案

如果你正在运行这在Visual Studio 2010中的调试情况下,你需要看调试输出(调试 - >窗口 - >输出)

If you're running this in a Visual Studio 2010 debugging instance, you'll need to look at the Debug Output (Debug -> Windows -> Output).

此外,你需要设置不仅错误报告模式,的也为警告(这是内存泄漏会报):

Moreover, you'll need to set the report mode for not only errors, but also for warnings (which is where memory leaks will be reported):

_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_DEBUG );
/* Alternatively:
 * _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
 * _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDERR );
 */

其中presented我下面的输出你的程序:

Which presented me the following output for your program:

Detected memory leaks!
Dumping objects ->
dump.c(14) : {86} normal block at 0x00834E50, 100 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
Object dump complete.
there is memmory leaks?: 1

这篇关于使用_CrtDumpMemoryLeaks显示数据来安慰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆