• <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>

            內(nèi)存溢出檢測學(xué)習(xí)

              最近發(fā)現(xiàn)CRT控制臺程序沒有TRACE和內(nèi)存溢出檢查,很郁悶。無聊中翻看MSDN的Memory Management and the Debug Heap篇,發(fā)現(xiàn)C的Debug版本用_malloc_dbg代替malloc,而_malloc_dbg者給數(shù)據(jù)堆加上一個(gè)控制頭組成鏈表,方便記錄溢出。原話如下:
              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:
              那個(gè)控制頭的數(shù)據(jù)結(jié)構(gòu)如下:
            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;

              這個(gè)nBlockUse有6種內(nèi)存塊,具體含義還沒有搞清楚,分別如下
            /* 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
              檢測內(nèi)存溢出用_CrtDumpMemoryLeaks(),在crtdbg.h中定義。有時(shí)間研究一下crtdbg.h文件。
              參考http://www.cnblogs.com/phinecos/archive/2009/10/29/1592604.html


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

            <2009年10月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            設(shè)計(jì)模式 網(wǎng)絡(luò)編程

            網(wǎng)絡(luò)

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            亚洲精品无码专区久久同性男 | 亚洲国产日韩综合久久精品| 久久香蕉综合色一综合色88| 青青草原综合久久大伊人精品| 激情久久久久久久久久| 2021国产精品久久精品| 国产V亚洲V天堂无码久久久| 精品人妻伦九区久久AAA片69| 区久久AAA片69亚洲| 久久精品国产男包| 久久精品中文騷妇女内射| 国产精品无码久久四虎| 亚洲精品乱码久久久久久蜜桃不卡| 久久久精品午夜免费不卡| 久久精品国产久精国产一老狼| 久久久久久九九99精品| 久久国产色AV免费观看| 久久国产免费| 99久久国产综合精品麻豆| 久久人人爽人人人人爽AV| 国产精自产拍久久久久久蜜| 精品久久久久久无码专区不卡| 亚洲人成无码www久久久| 亚洲成人精品久久| 精品蜜臀久久久久99网站| 亚洲精品高清国产一线久久| 三级韩国一区久久二区综合| 久久久久免费精品国产| 成人久久精品一区二区三区| 久久A级毛片免费观看| 中文字幕热久久久久久久| 性做久久久久久久久久久| 99久久婷婷国产综合精品草原| 久久精品欧美日韩精品| 久久亚洲美女精品国产精品| 亚洲精品无码久久久影院相关影片 | 亚洲级αV无码毛片久久精品| 久久婷婷五月综合97色直播| 久久亚洲国产精品123区| 久久久久亚洲AV成人网人人软件 | 伊人久久大香线焦AV综合影院|