• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            內存溢出檢測學習

              最近發現CRT控制臺程序沒有TRACE和內存溢出檢查,很郁悶。無聊中翻看MSDN的Memory Management and the Debug Heap篇,發現C的Debug版本用_malloc_dbg代替malloc,而_malloc_dbg者給數據堆加上一個控制頭組成鏈表,方便記錄溢出。原話如下:
              When you request a memory block, the debug heap manager allocates from the base heap a slightly larger block of memory than requested and returns a pointer to your portion of that block. For example, suppose your application contains the call: malloc( 10 ). In a release build, malloc would call the base heap allocation routine requesting an allocation of 10 bytes. In a debug build, however, malloc would call _malloc_dbg, which would then call the base heap allocation routine requesting an allocation of 10 bytes plus approximately 36 bytes of additional memory. All the resulting memory blocks in the debug heap are connected in a single linked list, ordered according to when they were allocated:
              那個控制頭的數據結構如下:
            typedef struct _CrtMemBlockHeader
            {
            // Pointer to the block allocated just before this one:
               struct _CrtMemBlockHeader *pBlockHeaderNext; 
            // Pointer to the block allocated just after this one:
               struct _CrtMemBlockHeader *pBlockHeaderPrev; 
               
            char *szFileName;   // File name
               int nLine;          // Line number
               size_t nDataSize;   // Size of user block
               int nBlockUse;      // Type of block
               long lRequest;      // Allocation number
            // Buffer just before (lower than) the user's memory:
               unsigned char gap[nNoMansLandSize];  
            } _CrtMemBlockHeader;

              這個nBlockUse有6種內存塊,具體含義還沒有搞清楚,分別如下
            /* Memory block identification */
            #define _FREE_BLOCK      0
            #define _NORMAL_BLOCK    1
            #define _CRT_BLOCK       2
            #define _IGNORE_BLOCK    3
            #define _CLIENT_BLOCK    4
            #define _MAX_BLOCKS      5
              檢測內存溢出用_CrtDumpMemoryLeaks(),在crtdbg.h中定義。有時間研究一下crtdbg.h文件。
              參考http://www.cnblogs.com/phinecos/archive/2009/10/29/1592604.html


            posted on 2009-11-03 22:53 gewala 閱讀(1063) 評論(0)  編輯 收藏 引用 所屬分類: C++

            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            導航

            統計

            常用鏈接

            留言簿

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            設計模式 網絡編程

            網絡

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久精品国产一区二区| 色综合久久中文字幕综合网 | 久久人人爽人人爽人人片AV东京热 | 丁香五月综合久久激情| 久久天天躁狠狠躁夜夜不卡 | 精品久久久久久成人AV| 国内精品久久国产大陆| 亚洲国产一成久久精品国产成人综合 | 狠狠综合久久综合88亚洲| 国产精品久久久久久久久| 无码人妻久久一区二区三区蜜桃| 日韩人妻无码一区二区三区久久| 久久国产精品久久| 久久精品国产色蜜蜜麻豆| 国产亚洲色婷婷久久99精品91| 亚洲国产精品无码成人片久久| 久久996热精品xxxx| av午夜福利一片免费看久久| 伊人久久大香线蕉AV一区二区 | 一本久久综合亚洲鲁鲁五月天| 国内精品九九久久久精品| 久久久午夜精品| 久久综合色区| 99久久综合狠狠综合久久| 99久久精品午夜一区二区| 伊人久久综合成人网| 亚洲欧洲中文日韩久久AV乱码| 99久久精品九九亚洲精品| 99久久久精品免费观看国产| 久久亚洲春色中文字幕久久久| 亚洲欧美国产精品专区久久| 久久久久国产一级毛片高清板 | 99国产精品久久| 久久久久人妻一区精品色| 亚洲AV无码久久| 一本久久a久久精品vr综合| 久久福利资源国产精品999| 久久亚洲国产成人影院网站| 国内精品久久久久久久coent| 91久久国产视频| 国产精品免费久久久久久久久|