<crtdbg.h> 的作用
来源:互联网 发布:新疆网络屏蔽 编辑:程序博客网 时间:2024/05/16 12:20
1、在调试状态下让win程在输出窗口中显示调试信息,可以用_RPTn 宏n为显示参数比如_RPT0(_CRT_WARN,"text");
_RPT1(_CRT_WARN,"%d", iTest); _RPT2(_CRT_WARN,"%d,%f", iTest, fTest);....依次类推,详细见msdn
2、侦测内存泄露用_CrtSetDbgFlag函数
_CrtDumpMemoryLeaks()在程序退出点之前调用会在输出中产生内存泄露信息,但是如果程序有多个退出点则无需
在所有退出点都调用该函数,取而代之的是简单的在main()一开始就首先调用
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);这样程序会在退出前自动调用_CrtDumpMemoryLeaks()
产生的信息类似:
Detected memory leaks!要在Dumpint objects -> 后面产生文件名的话来确定 泄露文件与代码行号的话(见上面红字部分)则需要在
Dumping objects ->
C:\PROGRAM FILES\VISUAL STUDIO\MyProjects\leaktest\leaktest.cpp(20) : {18}
normal block at 0x00780E80, 64 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
Object dump complete.
#include <crtdbg.h>之前加上宏#define _CRTDBG_MAP_ALLOC
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h> //msdn里面的例子加了该头文件
#include <crtdbg.h>
查找泄露技巧 使用_CrtSetBreakAlloc(long lBreakAlloc );函数参数为内存分配的次数,其值为调试信息的{}中的值
上面的例子为{18}
于是让程序自动在泄露处进入断点可以在_CrtSetDbgFlag后面添加函数_CrtSetBreakAlloc(18);然后调试程序时,程序
自动断在第18次分配内存的时的crt代码处,然后只要通过查看调用堆栈就可以轻松看到之前的泄露的代码了
0 0
- <crtdbg.h> 的作用
- 常用的 <crtdbg.h>
- 常用的crtdbg.h的一些说明
- #include <crtdbg.h>
- crtdbg.h: No such file or directory
- C++头文件crtdbg.h详解
- C/C++内存泄漏及检测 #include <crtdbg.h>
- stdafx.h的作用
- stdafx.h 的作用
- unistd.h的作用
- stdafx.h的作用
- stdafx.h的作用
- stdafx.h的作用
- stdafx.h的作用
- types.h的作用
- stdafx.h的作用
- stdafx.h的作用
- stdafx.h的作用
- leetcode 11
- 出题&题解
- ViewPager+Fragment+RadioGroup实现页面联动\点击切换
- 手写一个SqlHelper
- spark sql版本的单词统计代码
- <crtdbg.h> 的作用
- JSESSIONID与SESSION
- 自定义圆形图
- CodeForces 653 A. Bear and Three Balls(数学 ,快排)
- Easy-题目8:242. Valid Anagram
- POJ2488【DFS】
- Eclipse Debug快捷键 和 SVN各个字母含义
- Easy-题目9:171. Excel Sheet Column Number
- Mybatis 入门之resultMap与resultType讲解实例