【Visual Leak Detector】配置项 SelfTest – BBSMAP

您所在的位置:网站首页 如何打开map文件 【Visual Leak Detector】配置项 SelfTest – BBSMAP

【Visual Leak Detector】配置项 SelfTest – BBSMAP

2023-04-05 01:28| 来源: 网络整理| 查看: 265

说明

使用 VLD 内存泄漏检测工具辅助开发时整理的学习笔记。本篇介绍 VLD 配置文件中配置项 SelfTest 的使用方法。 同系列文章目录可见 《内存泄漏检测工具》目录

目录 说明 1. 配置文件使用说明 2. 设置是否开启泄漏自检 2.1 测试代码 2.2 SelfTest = off 时的输出 2.3 SelfTest = on 时的输出 2.4 输出结果对比

1. 配置文件使用说明

在程序中通过 #include "vld.h" 的方式检测内存泄漏时,VLD 首先会尝试在程序的生成目录下读取 vld.ini 文件,若未读取成功,则会尝试在 VLD 的安装目录下读取 vld.ini 文件,若仍未读取成功,则会使用内置的默认配置,内置的默认配置如果不动源码是无法更改的,因此通过修改相应目录下的 vld.ini 文件来定制 VLD 功能是最好的选择。当配置参数等号右边为空,或者给配置了不合法值时,在使用过程中会被程序重置到默认值。

2. 设置是否开启泄漏自检

参数名:SelfTest。

有效赋值:on,off。

默认值:off。

功能说明:打开或关闭自检模式。每次使用 VLD 时,除了检查需检测的程序是否有内存泄漏外,它也在检查自己是否有内存泄漏。将这个选项设置为 on 时,VLD 会有意地泄漏少量内存:一块大小为 22 bytes 的内存,填充内容为 'Memory Leak Self-Test' 这个长度为 21 的字符串。这个配置项提供了一种方法来测试 VLD 检查自身内存泄漏的能力,并验证该能力是否正常工作。这个配置项只对调试 VLD 自身有用。

2.1 测试代码 #include #include "vld.h" int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); 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 SelfTest = off 时的输出

VLD 输出报告:

Visual Leak Detector read settings from: D:\Program Files (x86)\Visual Leak Detector\vld.ini Visual Leak Detector Version 2.5.1 installed. No memory leaks detected. Visual Leak Detector is now exiting. 2.3 SelfTest = on 时的输出

VLD 输出报告:

Visual Leak Detector read settings from: D:\Program Files (x86)\Visual Leak Detector\vld.ini Visual Leak Detector Version 2.5.1 installed. Performing a memory leak self-test. No memory leaks detected. Visual Leak Detector is now exiting. ERROR: Visual Leak Detector: Detected a memory leak internal to Visual Leak Detector!! ---------- Block 6 at 0x01430810: 22 bytes ---------- Call Stack: vld.cpp (439): Full call stack not available. Data: 4D 65 6D 6F 72 79 20 4C 65 61 6B 20 53 65 6C 66 Memory.L eak.Self 2D 54 65 73 74 00 -Test... ........ Visual Leak Detector passed the memory leak self-test. 2.4 输出结果对比 当 SelfTest = off 时 VLD 没有故意泄漏内存。 当 SelfTest = on 时 VLD 故意泄漏了一块 22 bytes 的内存用于展示自检功能,同时没有影响到正常的检测功能。


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3