【Visual Leak Detector】配置项 MaxDataDump

yizhihongxing

说明

使用 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

本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:【Visual Leak Detector】配置项 MaxDataDump - Python技术站

(0)
上一篇 2023年4月18日
下一篇 2023年4月18日

相关文章

  • 【Visual Leak Detector】源码文件概览

    说明 使用 VLD 内存泄漏检测工具辅助开发时整理的学习笔记。本篇对 VLD 源码包中的各文件用途做个概述。同系列文章目录可见 《内存泄漏检测工具》目录 目录 说明 1. 整体概览 2. 文件夹 .teamcity 3 文件夹 lib 3.1 文件夹 cppformat(生成 libformat) 3.2 文件夹 dbghelp 3.3 文件夹 gtest(…

    C++ 2023年4月24日
    00
  • 驱动开发:内核使用IO/DPC定时器

    本章将继续探索驱动开发中的基础部分,定时器在内核中同样很常用,在内核中定时器可以使用两种,即IO定时器,以及DPC定时器,一般来说IO定时器是DDK中提供的一种,该定时器可以为间隔为N秒做定时,但如果要实现毫秒级别间隔,微秒级别间隔,就需要用到DPC定时器,如果是秒级定时其两者基本上无任何差异,本章将简单介绍IO/DPC这两种定时器的使用技巧。 首先来看IO…

    C++ 2023年4月18日
    00
  • 【Visual Leak Detector】核心源码剖析(VLD 2.5.1)

    说明 使用 VLD 内存泄漏检测工具辅助开发时整理的学习笔记。本篇对 VLD 2.5.1 源码做内存泄漏检测的思路进行剖析。同系列文章目录可见 《内存泄漏检测工具》目录 目录 说明 1. 源码获取 2. 源码文件概览 3. 源码剖析 3.1 通过 inline hook 修补 LdrpCallInitRoutine 3.2 通过 IAT hook 替换内存操…

    C++ 2023年5月11日
    00
  • 08、【算例】openfoam溃坝

    7.1 溃坝 官网目录:$FOAM_TUTORIALS/multiphase/interFoam/laminar/damBreak 7.1.1 介绍 本案例使用interFoam两相算法,基于流体体积分数(VOF)法,每个网格中的相体积分数(alpha)通过求解一个组分运输方程确定。物理属性基于这个相分数通过加权平均计算。 7.1.2 网格生成 blockM…

    C++ 2023年4月18日
    00
  • C++的对象和类

    一、问题引入 区分面向过程编程和面向对象编程的最大的特性就是 类,类是一种将抽象转换为用户定义类型的C++工具,它将数据表示和操纵数据的方法组合成一个整洁的包。 那么如何声明类、定义类、调用类? 以 C++ Primer Plus:中文版 (第六版) 的股票类举例说明。 二、解决过程 2-1 类抽象 股票类的抽象化 获得股票 增持股票 卖出股票 更新股票价格…

    C++ 2023年4月17日
    00
  • C++实现一个线程安全的map

    本文是使用ChatCPT生成的,最终的代码使用起来没问题。代码是通过两轮对话完善的,后面把对话合并后跑不出理想效果就没尝试了。 第一轮对话 请求 c++11实现一个线程安全的map,使用方法与std::map保持一致,实现[]运算符 回复 以下是一个简单的线程安全的map实现,可以使用[]运算符来访问和修改map中的元素: //代码省略,后面一起给出 该实现…

    C++ 2023年5月7日
    00
  • 【Visual Leak Detector】核心源码剖析(VLD 1.0)

    说明 使用 VLD 内存泄漏检测工具辅助开发时整理的学习笔记。本篇对 VLD 1.0 源码做内存泄漏检测的思路进行剖析。同系列文章目录可见 《内存泄漏检测工具》目录 目录 说明 1. 源码获取 2. 源码文件概览 3. 源码剖析 3.1 注册自定义 AllocHook 函数 3.2 存储调用堆栈信息 3.3 生成泄漏检测报告 4. 其他问题 4.1 如何区分…

    C++ 2023年4月27日
    00
  • L1-080 乘法口诀数列*(使用C++)

    L1-080 乘法口诀数列 分数 20 全屏浏览题目 切换布局 作者 陈越单位 浙江大学   本题要求你从任意给定的两个 1 位数字 a1​ 和 a2​ 开始,用乘法口诀生成一个数列 {an​},规则为从 a1​ 开始顺次进行,每次将当前数字与后面一个数字相乘,将结果贴在数列末尾。如果结果不是 1 位数,则其每一位都应成为数列的一项。 输入格式: 输入在一行…

    C++ 2023年4月18日
    00
合作推广
合作推广
分享本页
返回顶部