• <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久久免费国产精精品| 久久国产精品二国产精品| 欧美久久久久久精选9999| 久久久久九国产精品| 久久综合亚洲色一区二区三区| 久久久高清免费视频| 少妇精品久久久一区二区三区| 久久精品国产亚洲av麻豆小说| 亚洲国产天堂久久综合网站| 国产免费久久精品丫丫| 大香伊人久久精品一区二区| 久久精品国产亚洲精品2020| 久久久久久av无码免费看大片| 久久久久亚洲AV无码专区首JN| 99久久无色码中文字幕| 免费一级做a爰片久久毛片潮| 国产人久久人人人人爽| 久久亚洲欧洲国产综合| 国产精品久久亚洲不卡动漫| 久久夜色精品国产噜噜亚洲a| 久久精品国产免费| 亚洲va久久久噜噜噜久久狠狠| 久久高潮一级毛片免费| 国产精品一区二区久久国产| 最新久久免费视频| 久久国产高清一区二区三区| 俺来也俺去啦久久综合网| 久久国产精品无| 久久精品无码一区二区三区日韩| 99久久精品国产麻豆| 亚洲日本va中文字幕久久| 伊人久久无码精品中文字幕| 香港aa三级久久三级| 91精品国产综合久久婷婷| 日日噜噜夜夜狠狠久久丁香五月| 久久伊人精品一区二区三区| 久久精品成人一区二区三区| 97久久精品人人做人人爽| 精品国产91久久久久久久| 久久国产乱子伦免费精品| jizzjizz国产精品久久|