• memory leakage


    // compile with: cl testMemLeak.cpp -D_DEBUG /MTd -Od -Zi -W3 /link -verbose:lib /debug
    /*
     * This program concentrates on allocating and freeing memory
     * blocks to test the functionality of the _crtDbgFlag flag..
     */
     /*
     * The memory leakage info is output by OutputDebugString, which can be catched by DebugView
     *
     */

    // the 1st 3 line MUST put top most
    #define _CRTDBG_MAP_ALLOC
    #include <stdlib.h>
    #include <crtdbg.h>

    #include <vector>
    #include <windows.h>

    #ifdef _DEBUG
    //#define new   new(_NORMAL_BLOCK, __FILE__, __LINE__)
    #endif

    inline void EnableMemLeakCheck()
    {
       _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
    }

    void main()
    {
       EnableMemLeakCheck();
       //int* leak = new int[10];
       //malloc_(100);
       //_malloc_dbg(100, _NORMAL_BLOCK, __FILE__, __LINE__);
       std::vector<int> v(10);
       v.resize(1);
       v.reserve(100);
    }

    /*
    Modify xmemory
    void deallocate(pointer _Ptr, size_type)
            {    // deallocate object at _Ptr, ignore size
            operator delete(_Ptr);
            }
    to test memory leakage in STL
    */

  • 相关阅读:
    Java 多态
    Java 继承与抽象类
    Java 接口
    关于Oracle数据库故障诊断基础架构
    监控性能
    监视错误和警报
    内存管理参考
    使用自动内存管理
    内存架构概述
    关于内存管理
  • 原文地址:https://www.cnblogs.com/cutepig/p/1601165.html
Copyright © 2020-2023  润新知