說明
使用 VLD 記憶體泄漏檢測工具輔助開發時整理的學習筆記,本篇介紹 VLD 組態檔中配置項 MaxDataDump 的使用方法,同系列文章目錄可見 《記憶體泄漏檢測工具》目錄
目錄- 說明
- 1. 組態檔使用說明
- 2. 設定每個泄漏塊資料顯示的最大位元組數
- 2.1 測驗代碼
- 2.2 MaxDataDump 為空時的輸出
- 2.3 MaxDataDump = 0 時的輸出
- 2.4 MaxDataDump = 10 時的輸出
- 2.5 輸出結果對比
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.2,MSVC 2015 32bit,Debug 模式,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) 著作權協議,
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/548334.html
標籤:其他
下一篇:這幾個SQL語法的坑,你踩過嗎
