久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    1. <i id='4LpeG'><tr id='4LpeG'><dt id='4LpeG'><q id='4LpeG'><span id='4LpeG'><b id='4LpeG'><form id='4LpeG'><ins id='4LpeG'></ins><ul id='4LpeG'></ul><sub id='4LpeG'></sub></form><legend id='4LpeG'></legend><bdo id='4LpeG'><pre id='4LpeG'><center id='4LpeG'></center></pre></bdo></b><th id='4LpeG'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='4LpeG'><tfoot id='4LpeG'></tfoot><dl id='4LpeG'><fieldset id='4LpeG'></fieldset></dl></div>

      <small id='4LpeG'></small><noframes id='4LpeG'>

    2. <legend id='4LpeG'><style id='4LpeG'><dir id='4LpeG'><q id='4LpeG'></q></dir></style></legend>
    3. <tfoot id='4LpeG'></tfoot>
        <bdo id='4LpeG'></bdo><ul id='4LpeG'></ul>

    4. 使用 Visual Studio 在 C++ 應(yīng)用程序中查找內(nèi)存泄漏

      Finding memory leaks in a C++ application with Visual Studio(使用 Visual Studio 在 C++ 應(yīng)用程序中查找內(nèi)存泄漏)
      1. <legend id='aFPfl'><style id='aFPfl'><dir id='aFPfl'><q id='aFPfl'></q></dir></style></legend>
          <bdo id='aFPfl'></bdo><ul id='aFPfl'></ul>
            • <i id='aFPfl'><tr id='aFPfl'><dt id='aFPfl'><q id='aFPfl'><span id='aFPfl'><b id='aFPfl'><form id='aFPfl'><ins id='aFPfl'></ins><ul id='aFPfl'></ul><sub id='aFPfl'></sub></form><legend id='aFPfl'></legend><bdo id='aFPfl'><pre id='aFPfl'><center id='aFPfl'></center></pre></bdo></b><th id='aFPfl'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='aFPfl'><tfoot id='aFPfl'></tfoot><dl id='aFPfl'><fieldset id='aFPfl'></fieldset></dl></div>
              <tfoot id='aFPfl'></tfoot>

                <tbody id='aFPfl'></tbody>

                <small id='aFPfl'></small><noframes id='aFPfl'>

                本文介紹了使用 Visual Studio 在 C++ 應(yīng)用程序中查找內(nèi)存泄漏的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                問(wèn)題描述

                限時(shí)送ChatGPT賬號(hào)..

                在 Linux 中,我一直使用 valgrind 來(lái)檢查應(yīng)用程序中是否存在內(nèi)存泄漏.Windows 中的等價(jià)物是什么?這可以用 Visual Studio 2010 完成嗎?

                解決方案

                Visual Studio 2019 有一個(gè)不錯(cuò)的內(nèi)存分析工具,它可以在調(diào)試時(shí)交互使用或通過(guò)編程(無(wú)需調(diào)試)使用,我在這兩種情況下都展示了一個(gè)最小的例子在下面.

                主要思想是在進(jìn)程開(kāi)始和結(jié)束時(shí)對(duì)堆進(jìn)行快照,然后比較內(nèi)存狀態(tài)以檢測(cè)潛在的內(nèi)存泄漏.

                交互式

                創(chuàng)建以下 main.cpp 文件(在新的控制臺(tái)應(yīng)用程序中):

                #include int main(){int a = 1;字符* s = 新字符[17];strcpy_s(s,17,stackoverflow_pb");字符* ss = 新字符[14];strcpy_s(ss, 14, stackoverflow");刪除[] ss;返回0;}

                然后:

                1. 在第一行int a..."上放置一個(gè)斷點(diǎn)
                2. 點(diǎn)擊調(diào)試>窗口 >顯示診斷工具;并選擇內(nèi)存使用情況
                3. 然后調(diào)試代碼(F5),當(dāng)斷點(diǎn)被命中時(shí),點(diǎn)擊內(nèi)存使用情況摘要工具欄上的Take snapshot.
                4. 轉(zhuǎn)到最后一行return 0.."(跳過(guò)(F10)幾次)并拍攝另一個(gè)快照.
                5. 點(diǎn)擊第二個(gè)快照中的紅色箭頭(在內(nèi)存使用選項(xiàng)卡中)
                6. 這將打開(kāi)一個(gè)新的快照";選項(xiàng)卡,允許您將此快照與第一個(gè)(或另一個(gè))進(jìn)行比較并檢測(cè)內(nèi)存泄漏.在此示例中,變量 s (stackoverflow_pb) 存在內(nèi)存泄漏.您可以通過(guò)雙擊char[]"找到它.對(duì)象.

                以上過(guò)程的關(guān)鍵步驟如下圖所示:

                通過(guò)編程

                將代碼替換為以下內(nèi)容:

                #include #include windows.h"#define _CRTDBG_MAP_ALLOC//獲取更多細(xì)節(jié)#include #include //用于malloc和freeint main(){_CrtMemState 已售出;_CrtMemState sNew;_CrtMemState sDiff;_CrtMemCheckpoint(&sOld);//拍攝快照字符* s = 新字符[17];strcpy_s(s, 17, stackoverflow_pb");字符* ss = 新字符[14];strcpy_s(ss, 14, stackoverflow");刪除[] ss;_CrtMemCheckpoint(&sNew);//拍攝快照if (_CrtMemDifference(&sDiff, &sOld, &sNew))//如果有差異{OutputDebugString(L"-----------_CrtMemDumpStatistics ---------");_CrtMemDumpStatistics(&sDiff);OutputDebugString(L"-----------_CrtMemDumpAllObjectsSince ---------");_CrtMemDumpAllObjectsSince(&sOld);OutputDebugString(L"-----------_CrtDumpMemoryLeaks ---------");_CrtDumpMemoryLeaks();}返回0;}

                它做同樣的事情,但通過(guò)代碼,所以你可以將它集成到自動(dòng)構(gòu)建系統(tǒng)中,功能


                要獲取更多信息,請(qǐng)參閱以下鏈接:

                • 交互式分析:測(cè)量 Visual Studio 中的內(nèi)存使用情況
                • 通過(guò)編程:使用 CRT 庫(kù)查找內(nèi)存泄漏 和 CRT 調(diào)試堆文件(也用于堆損壞)

                In Linux, I have been using valgrind for checking if there are memory leaks in an application. What is the equivalent in Windows? Can this be done with Visual Studio 2010?

                解決方案

                Visual Studio 2019 has a decent memory analysis tool, it may be used interactively while debugging or by programming (without debugging), I show a minimal example in both cases in the following.

                The main idea is to take a snapshot of the heap at the beginning and at the end of the process, then to compare the states of memory to detect potential memory leaks.

                Interactively

                Create the following main.cpp file (in a new console application) :

                #include <string.h>
                int main()
                {
                 int a = 1;
                 char* s = new char[17];
                 strcpy_s(s,17,"stackoverflow_pb");
                 char* ss = new char[14];
                 strcpy_s(ss, 14,"stackoverflow");
                 delete[] ss;
                 return 0;
                }
                

                Then :

                1. Put a breakpoint on the first line "int a..."
                2. Click Debug > Windows > Show Diagnostic Tools; and pick memory usage
                3. Then debug the code (F5), when the breakpoint is hit, click Take snapshot on the Memory Usage summary toolbar.
                4. Go to the last line "return 0.." (step over (F10) several times) and take another snapshot.
                5. Click on the red arrow in the second snapshot (in memory usage tab)
                6. this will open a new "snapshot" tab that permits you to compare this snapshot with the first one (or another one) and to detect memory leaks. In this example there is a memory leak for variable s (stackoverflow_pb). You can find it by double click the "char[]" object.

                The key steps of the above procedure are shown in the following image:

                By programming

                Replace the code with the following:

                #include <iostream>
                
                #include "windows.h"
                #define _CRTDBG_MAP_ALLOC //to get more details
                #include <stdlib.h>  
                #include <crtdbg.h>   //for malloc and free
                int main()
                {
                    _CrtMemState sOld;
                    _CrtMemState sNew;
                    _CrtMemState sDiff;
                    _CrtMemCheckpoint(&sOld); //take a snapshot
                    char* s = new char[17];
                    strcpy_s(s, 17, "stackoverflow_pb");
                    char* ss = new char[14];
                    strcpy_s(ss, 14, "stackoverflow");
                    delete[] ss;
                    _CrtMemCheckpoint(&sNew); //take a snapshot 
                    if (_CrtMemDifference(&sDiff, &sOld, &sNew)) // if there is a difference
                    {
                        OutputDebugString(L"-----------_CrtMemDumpStatistics ---------");
                        _CrtMemDumpStatistics(&sDiff);
                        OutputDebugString(L"-----------_CrtMemDumpAllObjectsSince ---------");
                        _CrtMemDumpAllObjectsSince(&sOld);
                        OutputDebugString(L"-----------_CrtDumpMemoryLeaks ---------");
                        _CrtDumpMemoryLeaks();
                    }
                    return 0;
                }
                

                It does the same thing but by code, so you can integrate it in an automatic build system, the functions _CrtMemCheckpoint take the snapshots and _CrtMemDifference compare the memory states of snapshot and returns true is they are different.

                Since it is the case, it enters the conditional block and prints details about the leaks via several functions (see _CrtMemDumpStatistics , _CrtMemDumpAllObjectsSince and _CrtDumpMemoryLeaks - the latter doesn't require snapshots).

                To see the output, put a break point in the last line "return 0", hit F5 and look at the debug console. Here is the output :


                To get more information, see the following links :

                • Interactive analysis : Measure memory usage in Visual Studio
                • via programming : Find memory leaks with the CRT library and CRT debug Heap Files (for heap corruption also)

                這篇關(guān)于使用 Visual Studio 在 C++ 應(yīng)用程序中查找內(nèi)存泄漏的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                相關(guān)文檔推薦

                Why do two functions have the same address?(為什么兩個(gè)函數(shù)的地址相同?)
                Why the initializer of std::function has to be CopyConstructible?(為什么 std::function 的初始化程序必須是可復(fù)制構(gòu)造的?)
                mixing templates with polymorphism(混合模板與多態(tài)性)
                When should I use the keyword quot;typenamequot; when using templates(我什么時(shí)候應(yīng)該使用關(guān)鍵字“typename?使用模板時(shí))
                Dependent name resolution amp; namespace std / Standard Library(依賴名稱(chēng)解析命名空間 std/標(biāo)準(zhǔn)庫(kù))
                gcc can compile a variadic template while clang cannot(gcc 可以編譯可變參數(shù)模板,而 clang 不能)

                  <tfoot id='6socf'></tfoot>

                    <legend id='6socf'><style id='6socf'><dir id='6socf'><q id='6socf'></q></dir></style></legend>
                  1. <i id='6socf'><tr id='6socf'><dt id='6socf'><q id='6socf'><span id='6socf'><b id='6socf'><form id='6socf'><ins id='6socf'></ins><ul id='6socf'></ul><sub id='6socf'></sub></form><legend id='6socf'></legend><bdo id='6socf'><pre id='6socf'><center id='6socf'></center></pre></bdo></b><th id='6socf'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='6socf'><tfoot id='6socf'></tfoot><dl id='6socf'><fieldset id='6socf'></fieldset></dl></div>
                      <bdo id='6socf'></bdo><ul id='6socf'></ul>

                          <tbody id='6socf'></tbody>
                      • <small id='6socf'></small><noframes id='6socf'>

                        1. 主站蜘蛛池模板: 在线视频一区二区 | 免费一级黄色录像 | 精品小视频 | 国产成人在线播放 | 黄色综合网| 亚洲天堂网在线观看 | 国产黄色免费网站 | 国产一区欧美 | 九九热精品在线观看 | 欧美激情一区二区三区 | 日本激情网 | 欧美一区免费 | 婷婷伊人网| 一级片在线播放 | 国产午夜av | 一区二区三区免费在线观看 | 四虎wz| 双性呜呜宫交受不住了h | 久久精品一区二区三区四区五区 | 中文字幕av久久爽av | 五月天婷婷网站 | 亚洲最大av网站 | 在线亚洲天堂 | 欧美黑人一区二区三区 | 国产日本在线观看 | 色综合久久久久 | 国产三级成人 | 免费黄色小说网站 | 超碰人人在线 | 午夜精品久久久久久 | 国产区视频在线观看 | 日本高清在线观看 | 一区二区三区视频 | av网站免费在线观看 | 国产色一区 | 欧美伦理一区二区 | 亚洲黄色在线视频 | 91精品久久久久久粉嫩 | 天天插天天透 | 五月婷综合 | 免费av在线|