• <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 閱讀(1067) 評論(0)  編輯 收藏 引用 所屬分類: C++

            <2025年6月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            導航

            統計

            常用鏈接

            留言簿

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            設計模式 網絡編程

            網絡

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            99久久精品费精品国产| 久久久久亚洲?V成人无码| 久久久久久精品无码人妻| 精品久久久无码21p发布| 欧美黑人激情性久久| 免费观看久久精彩视频| 无码8090精品久久一区| 人妻久久久一区二区三区| 青青草原综合久久| 亚洲午夜久久久久妓女影院 | 国产福利电影一区二区三区久久老子无码午夜伦不 | 99久久精品国内| 久久天天躁狠狠躁夜夜2020| 一本色综合网久久| 99久久国产亚洲高清观看2024 | 中文字幕一区二区三区久久网站 | 久久婷婷五月综合97色一本一本 | 国内精品久久久久久久coent| 久久久久久久波多野结衣高潮| 久久亚洲欧美日本精品| 99精品国产99久久久久久97| 久久夜色撩人精品国产小说| 久久国产乱子精品免费女| 伊人久久综合精品无码AV专区| 久久久久国产亚洲AV麻豆| 久久美女人爽女人爽| 99久久99这里只有免费费精品| 久久这里有精品| 久久精品成人免费国产片小草 | 久久久久亚洲AV无码专区桃色 | 国产精品久久久久蜜芽| 久久亚洲国产成人影院网站| 亚洲国产精品久久久久婷婷软件 | 久久久WWW成人| 国产三级观看久久| 国产高潮久久免费观看| 狠狠综合久久综合中文88| 7国产欧美日韩综合天堂中文久久久久 | 久久久久亚洲AV无码专区网站| 国产精品日韩深夜福利久久| 国产99久久九九精品无码|