【Visual Leak Detector】配置項 MaxDataDump

来源:https://www.cnblogs.com/young520/archive/2023/03/27/17263170.html
-Advertisement-
Play Games

使用 VLD 記憶體泄漏檢測工具輔助開發時整理的學習筆記。本篇介紹 VLD 配置文件中配置項 MaxDataDump 的使用方法。 ...


說明

使用 VLD 記憶體泄漏檢測工具輔助開發時整理的學習筆記。本篇介紹 VLD 配置文件中配置項 MaxDataDump 的使用方法。同系列文章目錄可見 《記憶體泄漏檢測工具》目錄

目錄


1. 配置文件使用說明

在程式中通過 #include "vld.h" 的方式檢測記憶體泄漏時,VLD 首先會嘗試在程式的生成目錄下讀取 vld.ini 文件,若未讀取成功,則會嘗試在 VLD 的安裝目錄下讀取 vld.ini 文件,若仍未讀取成功,則會使用內置的預設配置,內置的預設配置如果不動源碼是無法更改的,因此通過修改相應目錄下的 vld.ini 文件來定製 VLD 功能是最好的選擇。當配置參數等號右邊為空,或者給配置了不合法值時,在使用過程中會被程式重置到預設值。

2. 設置每個泄漏塊數據顯示的最大位元組數

參數名MaxDataDump

有效賦值0~4294967295

預設值256

功能說明:設置每個泄漏塊數據顯示的最大位元組數。如果為零,則完全不顯示記憶體數據,只顯示調用堆棧。當泄漏塊很大時,把這個值設置得比較小可以使輸出看起來邏輯更清晰。

2.1 測試代碼

#include <QCoreApplication>
#include "vld.h"

void testFun(int i)
{
    int *ptr = new int[i];
    printf("ptr = %08x.\n", ptr);
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    testFun(10);

    return a.exec();
}

測試環境:QT 5.9.2MSVC 2015 32bitDebug 模式,VLD 版本為 2.5.1,VLD 配置文件只對該參數做修改,測試工程所在路徑為:E:\Cworkspace\Qt 5.9\QtDemo\testVLD

2.2 MaxDataDump 為空時的輸出

標準輸出窗顯示:

ptr = 007b2380.

VLD 輸出報告:

Visual Leak Detector read settings from: D:\Program Files (x86)\Visual Leak Detector\vld.ini
Visual Leak Detector Version 2.5.1 installed.
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 1 at 0x007B2380: 40 bytes ----------
  Leak Hash: 0xEA2B3F1B, Count: 1, Total 40 bytes
  Call Stack (TID 20816):
    ucrtbased.dll!malloc()
    f:\dd\vctools\crt\vcstartup\src\heap\new_array.cpp (15): testVLD.exe!operator new[]() + 0x9 bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (6): testVLD.exe!testFun() + 0x19 bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (14): testVLD.exe!main() + 0x7 bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (74): testVLD.exe!invoke_main() + 0x1B bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (264): testVLD.exe!__scrt_common_main_seh() + 0x5 bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (309): testVLD.exe!__scrt_common_main()
    f:\dd\vctools\crt\vcstartup\src\startup\exe_main.cpp (17): testVLD.exe!mainCRTStartup()
    KERNEL32.DLL!BaseThreadInitThunk() + 0x19 bytes
    ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0x11E bytes
    ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0xEE bytes
  Data:
    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........
    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........
    CD CD CD CD    CD CD CD CD                                   ........ ........


Visual Leak Detector detected 1 memory leak (76 bytes).
Largest number used: 76 bytes.
Total allocations: 76 bytes.
Visual Leak Detector is now exiting.

2.3 MaxDataDump = 0 時的輸出

標準輸出窗顯示:

ptr = 013d1f78.

VLD 輸出報告:

Visual Leak Detector read settings from: D:\Program Files (x86)\Visual Leak Detector\vld.ini
Visual Leak Detector Version 2.5.1 installed.
    Suppressing data dumps.
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 1 at 0x013D1F78: 40 bytes ----------
  Leak Hash: 0xEA2B3F1B, Count: 1, Total 40 bytes
  Call Stack (TID 24860):
    ucrtbased.dll!malloc()
    f:\dd\vctools\crt\vcstartup\src\heap\new_array.cpp (15): testVLD.exe!operator new[]() + 0x9 bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (6): testVLD.exe!testFun() + 0x19 bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (14): testVLD.exe!main() + 0x7 bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (74): testVLD.exe!invoke_main() + 0x1B bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (264): testVLD.exe!__scrt_common_main_seh() + 0x5 bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (309): testVLD.exe!__scrt_common_main()
    f:\dd\vctools\crt\vcstartup\src\startup\exe_main.cpp (17): testVLD.exe!mainCRTStartup()
    KERNEL32.DLL!BaseThreadInitThunk() + 0x19 bytes
    ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0x11E bytes
    ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0xEE bytes


Visual Leak Detector detected 1 memory leak (76 bytes).
Largest number used: 76 bytes.
Total allocations: 76 bytes.
Visual Leak Detector is now exiting.

2.4 MaxDataDump = 10 時的輸出

標準輸出窗顯示:

ptr = 00541870.

VLD 輸出報告:

Visual Leak Detector read settings from: D:\Program Files (x86)\Visual Leak Detector\vld.ini
Visual Leak Detector Version 2.5.1 installed.
    Limiting data dumps to 10 bytes.
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 1 at 0x00541870: 40 bytes ----------
  Leak Hash: 0xEA2B3F1B, Count: 1, Total 40 bytes
  Call Stack (TID 18640):
    ucrtbased.dll!malloc()
    f:\dd\vctools\crt\vcstartup\src\heap\new_array.cpp (15): testVLD.exe!operator new[]() + 0x9 bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (6): testVLD.exe!testFun() + 0x19 bytes
    e:\cworkspace\qt 5.9\qtdemo\testvld\main.cpp (14): testVLD.exe!main() + 0x7 bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (74): testVLD.exe!invoke_main() + 0x1B bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (264): testVLD.exe!__scrt_common_main_seh() + 0x5 bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (309): testVLD.exe!__scrt_common_main()
    f:\dd\vctools\crt\vcstartup\src\startup\exe_main.cpp (17): testVLD.exe!mainCRTStartup()
    KERNEL32.DLL!BaseThreadInitThunk() + 0x19 bytes
    ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0x11E bytes
    ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0xEE bytes
  Data:
    CD CD CD CD    CD CD CD CD    CD CD                          ........ ........


Visual Leak Detector detected 1 memory leak (76 bytes).
Largest number used: 76 bytes.
Total allocations: 76 bytes.
Visual Leak Detector is now exiting.

2.5 輸出結果對比

  • MaxDataDump 為空時,使用預設值 256,由於泄漏塊大小小於 256 bytes,因此泄漏記憶體中的數據 40 bytes 全部顯示了出來。
  • MaxDataDump = 0 時,不顯示記憶體數據,只顯示調用堆棧。
  • MaxDataDump = 10 時,只顯示前 10 bytes 的記憶體數據。

本文作者:木三百川

本文鏈接:https://www.cnblogs.com/young520/p/17263170.html

版權聲明:本文系博主原創文章,著作權歸作者所有。商業轉載請聯繫作者獲得授權,非商業轉載請附上出處鏈接。遵循 署名-非商業性使用-相同方式共用 4.0 國際版 (CC BY-NC-SA 4.0) 版權協議。


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 插槽基本介紹 在開發中,我們會經常封裝一個個可復用的組件: 前面我們會通過props傳遞給組件一些數據,讓組件來進行展示; 但是為了讓這個組件具備更強的通用性,我們不能將組件中的內容限製為固定的div、span等等這些元素; 比如某種情況下我們使用組件,希望組件顯示的是一個按鈕,某種情況下我們使用組 ...
  • 定義 定義一系列的演算法,將他們一個個封裝起來,使他們直接可以相互替換。 演算法:就是寫的邏輯可以是你任何一個功能函數的邏輯 封裝:就是把某一功能點對應的邏輯給抽出來 可替換:建立在封裝的基礎上,這些獨立的演算法可以很方便的替換 通俗的理解就是,把你的演算法(邏輯)封裝到不同的策略中,在不同的策略中是互相獨 ...
  • 訪問者模式(Visitor Pattern)是一種行為型設計模式,用於將操作與其所操作的對象分離開來。該模式的核心思想是將操作封裝在一個訪問者對象中,而不是分散在各個對象中。通過將操作與對象分離開來,訪問者模式可以在不修改對象結構的情況下,添加新的操作。 在前端開發中,訪問者模式通常用於處理DOM樹 ...
  • mounted: () { this.getList('', (data) => { console.log(data); }) } methods: { getList (condition) { get_list({...condition}).then(res => { if (res.dat ...
  • 在Vue $mount過程中,我們需要把模版編譯成render函數,整體實現可以分為三部分: parse、optimize、codegen。 ...
  • 1. 響應式編程 1.1. 使用基於事件的範式處理非同步數據流 1.2. 和非同步編程提供了相同的性能優勢 1.3. 能夠擴展程式(特別是擴展I/O)以處理很多連接和數據源 2. 非阻塞I/O 2.1. 有效擴展伺服器的基礎 2.2. 允許伺服器用相對較少的線程處理相對較多的連接 2.2.1. 傳統的服 ...
  • 關於商業認知 2022 年復盤了過去幾年的項目經歷:很多項目商業都沒開始就死了,能商業化閉環 & 能持續一段時間的一隻手數量都沒有。 從 2022 年幾個月陸續復盤中,收穫了不少商業相關心得: 心得:一定要選合適自己方向的項目 以前我對戰略、方向的思考是極少的,很容易陷入達克效應(鄧寧-克魯格效應) ...
  • 本文已經收錄到Github倉庫,該倉庫包含電腦基礎、Java基礎、多線程、JVM、資料庫、Redis、Spring、Mybatis、SpringMVC、SpringBoot、分散式、微服務、設計模式、架構、校招社招分享等核心知識點,歡迎star~ Github地址 大家好,我是大彬~ 今天給大家分 ...
一周排行
    -Advertisement-
    Play Games
  • 前言 插件化的需求主要源於對軟體架構靈活性的追求,特別是在開發大型、複雜或需要不斷更新的軟體系統時,插件化可以提高軟體系統的可擴展性、可定製性、隔離性、安全性、可維護性、模塊化、易於升級和更新以及支持第三方開發等方面的能力,從而滿足不斷變化的業務需求和技術挑戰。 一、插件化探索 在WPF中我們想要開 ...
  • 歡迎ReaLTaiizor是一個用戶友好的、以設計為中心的.NET WinForms項目控制項庫,包含廣泛的組件。您可以使用不同的主題選項對項目進行個性化設置,並自定義用戶控制項,以使您的應用程式更加專業。 項目地址:https://github.com/Taiizor/ReaLTaiizor 步驟1: ...
  • EDP是一套集組織架構,許可權框架【功能許可權,操作許可權,數據訪問許可權,WebApi許可權】,自動化日誌,動態Interface,WebApi管理等基礎功能於一體的,基於.net的企業應用開發框架。通過友好的編碼方式實現數據行、列許可權的管控。 ...
  • Channel 是乾什麼的 The System.Threading.Channels namespace provides a set of synchronization data structures for passing data between producers and consume ...
  • efcore如何優雅的實現按年分庫按月分表 介紹 本文ShardinfCore版本 本期主角: ShardingCore 一款ef-core下高性能、輕量級針對分表分庫讀寫分離的解決方案,具有零依賴、零學習成本、零業務代碼入侵適配 距離上次發文.net相關的已經有很久了,期間一直在從事java相關的 ...
  • 前言 Spacesniffer 是一個免費的文件掃描工具,通過使用樹狀圖可視化佈局,可以立即瞭解大文件夾的位置,幫助用戶處理找到這些文件夾 當前系統C盤空間 清理後系統C盤空間 下載 Spacesniffer 下載地址:https://spacesniffer.en.softonic.com/dow ...
  • EDP是一套集組織架構,許可權框架【功能許可權,操作許可權,數據訪問許可權,WebApi許可權】,自動化日誌,動態Interface,WebApi管理等基礎功能於一體的,基於.net的企業應用開發框架。通過友好的編碼方式實現數據行、列許可權的管控。 ...
  • 一、ReZero簡介 ReZero是一款.NET中間件 : 全網唯一開源界面操作就能生成API , 可以集成到任何.NET6+ API項目,無破壞性,也可讓非.NET用戶使用exe文件 免費開源:MIT最寬鬆協議 , 一直從事開源事業十年,一直堅持開源 1.1 純ReZero開發 適合.Net Co ...
  • 一:背景 1. 講故事 停了一個月沒有更新文章了,主要是忙於寫 C#內功修煉系列的PPT,現在基本上接近尾聲,可以回頭繼續更新這段時間分析dump的一些事故報告,有朋友微信上找到我,說他們的系統出現了大量的http超時,程式不響應處理了,讓我幫忙看下怎麼回事,dump也抓到了。 二:WinDbg分析 ...
  • 開始做項目管理了(本人3年java,來到這邊之後真沒想到...),天天開會溝通整理需求,他們講話的時候忙裡偷閑整理一下常用的方法,其實語言還是有共通性的,基本上看到方法名就大概能猜出來用法。出去打水的時候看到外面太陽好好,真想在外面坐著曬太陽,回來的時候好兄弟三年前送給我的鍵盤D鍵不靈了,在打"等待 ...