• <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ù)堆加上一個控制頭組成鏈表,方便記錄溢出。原話如下:
              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:
              那個控制頭的數(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;

              這個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中定義。有時間研究一下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

            導(dǎo)航

            統(tǒng)計

            常用鏈接

            留言簿

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

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

            網(wǎng)絡(luò)

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            97久久超碰国产精品2021| 久久精品国产亚洲AV不卡| 亚洲欧美精品一区久久中文字幕| 久久久久久久亚洲精品| 99精品久久久久久久婷婷| 久久综合丁香激情久久| 午夜精品久久久久| 亚洲色欲久久久久综合网| 国色天香久久久久久久小说| 久久99国产精品二区不卡| 亚洲国产精品成人AV无码久久综合影院| 久久精品桃花综合| 日本福利片国产午夜久久| 77777亚洲午夜久久多喷| 国产日韩久久久精品影院首页| 99久久国产精品免费一区二区| 久久se精品一区二区影院| 国产精品无码久久久久久| 久久笫一福利免费导航 | 国产精品美女久久久久av爽 | 国产精品内射久久久久欢欢| 免费无码国产欧美久久18| 色综合久久精品中文字幕首页| 少妇久久久久久久久久| 一日本道伊人久久综合影| 一级做a爰片久久毛片16| 久久精品国产亚洲AV无码娇色| 久久久久久国产精品无码下载| 国产激情久久久久影院老熟女| 99久久免费国产特黄| 亚洲精品乱码久久久久久按摩 | 狠狠色噜噜色狠狠狠综合久久| 欧美一级久久久久久久大| 久久久久无码专区亚洲av| 久久国产精品免费一区| 久久久久久久综合综合狠狠| 久久久久久久国产免费看| 天天做夜夜做久久做狠狠| 亚洲精品97久久中文字幕无码 | 久久精品国产亚洲精品2020 | 亚洲愉拍99热成人精品热久久 |