zoukankan      html  css  js  c++  java
  • c++中捕捉内存泄露、异常

    //在Watch面板加上可以观察当前断点处最后一条异常信息:@err,hr

    #include "stdafx.h" #include <iostream> using namespace std; #ifdef _DEBUG #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__) #else #define DEBUG_CLIENTBLOCK #endif #define _CRTDBG_MAP_ALLOC #include <stdlib.h> #include <crtdbg.h> #include <string.h> #include <stdio.h> #ifdef _DEBUG #define new DEBUG_CLIENTBLOCK #endif int _tmain(int argc, _TCHAR* argv[]) { _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);      //_CrtSetBreakAlloc(52);
    char* d; int *p; d= (char*)malloc(100); p = new int; /***这两行注释与不注释结果不一样 free(d); delete p; ***/ _CrtDumpMemoryLeaks(); system("pause"); return 0; }

      在Visual C++ 中,可以在监视窗口添加 $err,hr
    一行来实时现实错误。调试过程中,该项相当于在每次调用API函数之后调用GetLastError函数。其值由两部分组成,一个是错误代码(十六进制),另一个是错误代码所对应的文本提示。该方法支持多语言

  • 相关阅读:
    算法图解
    Cairo graphics tutorial
    远程对象调用
    异步和多线程的关系
    jQuery调用api
    GTK# tutorial
    DLT
    protobuf入门笔记
    PDO讲解
    数据库练习——分页查询
  • 原文地址:https://www.cnblogs.com/chuncn/p/2429305.html
Copyright © 2011-2022 走看看