ImageVerifierCode 换一换
格式:DOCX , 页数:5 ,大小:17.85KB ,
资源ID:15176983      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/15176983.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(VC中的一些调试技巧Word文件下载.docx)为本站会员(b****2)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

VC中的一些调试技巧Word文件下载.docx

1、43:26点击:6799 毕业快一年,做了2个项目,都是在别人的代码上作开发,苦不堪言:bug 实在是太多。这一年中有大半的时间是在改别人的bug, 也积累了一些经验,和大家分享。我的方法大多数都来自Windows程序调试(英文名 Debugging Windows Programs)。那本书里讲了很多方法,我只挑对我自己帮助最大的:1 调试内存破坏。这种bug的表现就是不定时,不定地方的崩溃。这种bug我一共碰到2次,每一次都花了很长时间,尤其是第二次,花了大家三天时间。其原因是堆(heap)被破坏掉了。我的方法是这样的:在可能出现问题的地方加上对堆的检查,用如下代码:/ Get the c

2、urrent state of the flag/ and store it in a temporary variableint tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );/ Turn On (OR) - Keep freed memory blocks in the/ heaps linked list and mark them as freedtmpFlag |= _CRTDBG_CHECK_ALWAYS_DF;/ Set the new state for the flag_CrtSetDbgFlag( tmpFlag );int

3、 *nn =new int;delete nn;/ Turn Off (AND) - prevent _CrtCheckMemory from/ being called at every allocation request,It will cause much timetmpFlag &= _CRTDBG_CHECK_ALWAYS_DF;如果之前堆已经坏掉了,那么程序(Debug版)就会在分配内存的地方中断,在这儿是int *nn =new int; 第一次破坏堆的代码是这样:typedef struct aa int a; AA;AA sn;int i = 0;for(i=0;i18 n

4、ormal 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.If you can not see the dump information in VC, you can add the code to the file crtdbg.h:#ifdef _DEBUG#define _CRTDBG_MAP_ALLOC#define _INC_MALLOC#include / custom functions declarati

5、on (ATL + BETA version problems)extern Cvoid * _cdecl _alloca(size_t);#define alloca _alloca#endifAs you can see, _CrtDumpMemoryLeaks gives you much more useful information when _CRTDBG_MAP_ALLOC is defined. Without _CRTDBG_MAP_ALLOC defined, the display shows you: the memory allocation number (insi

6、de the curly braces). the type of block (normal, client, or CRT). the memory location in hexadecimal form. the size of the block in bytes. the contents of the first 16 bytes (also in hexadecimal). You can run your program twice in the same way, then you can find that the memory allocation number of

7、the leaked memory is always the same, so you can use the memory allocation number to find the memory leak; directly to say, you can break the program by memory allocation number.The below is taken from MSDN(Detecting and Isolating Memory Leaks Using Microsoft Visual C+)Setting a Breakpoint on a Memo

8、ry Allocation NumberThe file name and line number in the memory leak report tell you where leaked memory is allocated, but knowing where the memory is allocated is not always sufficient to identify the problem. Often an allocation will be called many times during a run of the program, but it may lea

9、k memory only on certain calls. To identify the problem, you must know not only where the leaked memory is allocated but also the conditions under which the leak occurs. The piece of information that makes it possible for you to do this is the memory allocation number. This is the number that appear

10、s in curly braces, after the file name and line number when those are displayed. For example, in the following output, “18” is the memory allocation number. It means the leaked memory is the 18th block of memory allocated in your program.C:PROGRAM FILESVISUAL STUDIOMyProjectsleaktestleaktest.cpp(20)

11、 : 18 normal block at 0x00780E80, 64 bytes long.The CRT library counts all memory blocks allocated during a run of the program, including memory allocated by the CRT library itself or by other libraries, such as MFC. Therefore, an object with allocation number n will be the nth object allocated in y

12、our program but may not be the nth object allocated by your code. (In most cases, it will not be.)You can use the allocation number to set a breakpoint at the location where memory is allocated. To do this, set a location breakpoint near the start of your program. When your program breaks at that po

13、int, you can set such a memory allocation breakpoint from the QuickWatch dialog box or the Watch window. In the Watch window, for example, type the following expression in the Name column:_crtBreakAllocIf you are using the multithreaded dynamic-link library (DLL) version of the CRT library (the /MD option), you must include the context operator, as shown here:,msvcrtd.dll_crtBreakAllocNow

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1