设为首页 加入收藏

TOP

【Visual Leak Detector】库的 22 个 API 使用说明(一)
2023-07-23 13:32:43 】 浏览:150
Tags:Visual Leak Detector API

说明

使用 VLD 内存泄漏检测工具辅助开发时整理的学习笔记。本篇主要介绍 VLD 库提供的 22 个外部接口。同系列文章目录可见 《内存泄漏检测工具》目录


1. 头文件简介

VLD 2.5.1 安装 完成后,安装目录的 include 文件夹下有两个头文件:vld.hvld_def.h,其中 vld.h 文件会 #include "vld_def.h",因此在实际使用时,项目中要同时添加这两个头文件(或将这两个文件放在编译器的搜索路径中),但只需包含 vld.h 文件。

2. 文件 vld_def.h 简介

这个文件里主要以宏的形式定义了 15 个 VLD 配置项的掩码,这 15 个配置项与 vld.ini 配置文件中的 14 个配置项不是完全对应的,将这些配置项掩码与 vld.h 文件中的接口结合起来用,可以实现在运行过程中对 VLD 的配置进行动态修改。其中 9 个配置项可作为接口 VLDSetOptions 的输入,另外 4 个配置项可作为接口 VLDSetReportOptions 的输入,剩余的 2 个配置项分别是 VLD_OPT_SELF_TESTVLD_OPT_VLDOFF,其中 VLD_OPT_SELF_TEST 只能通过修改 vld.ini 文件中的 SelfTest 进行设置(详见 配置项 SelfTest),VLD_OPT_VLDOFF 只能通过修改 vld.ini 文件中的 VLD 进行设置(详见 配置项 VLD),当 VLD_OPT_VLDOFF 被设置后,所有接口也都会变得不可用。

#define VLD_OPT_AGGREGATE_DUPLICATES    0x0001 //   If set, aggregate duplicate leaks in the leak report.
#define VLD_OPT_MODULE_LIST_INCLUDE     0x0002 //   If set, modules in the module list are included, all others are excluded.
#define VLD_OPT_REPORT_TO_DEBUGGER      0x0004 //   If set, the memory leak report is sent to the debugger.
#define VLD_OPT_REPORT_TO_FILE          0x0008 //   If set, the memory leak report is sent to a file.
#define VLD_OPT_SAFE_STACK_WALK         0x0010 //   If set, the stack is walked using the "safe" method (StackWalk64).
#define VLD_OPT_SELF_TEST               0x0020 //   If set, perform a self-test to verify memory leak self-checking.
#define VLD_OPT_SLOW_DEBUGGER_DUMP      0x0040 //   If set, inserts a slight delay between sending output to the debugger.
#define VLD_OPT_START_DISABLED          0x0080 //   If set, memory leak detection will initially disabled.
#define VLD_OPT_TRACE_INTERNAL_FRAMES   0x0100 //   If set, include useless frames (e.g. internal to VLD) in call stacks.
#define VLD_OPT_UNICODE_REPORT          0x0200 //   If set, the leak report will be encoded UTF-16 instead of ASCII.
#define VLD_OPT_VLDOFF                  0x0400 //   If set, VLD will be completely deactivated. It will not attach to any modules.
#define VLD_OPT_REPORT_TO_STDOUT        0x0800 //   If set, the memory leak report is sent to stdout.
#define VLD_OPT_SKIP_HEAPFREE_LEAKS     0x1000 //   If set, VLD skip HeapFree memory leaks.
#define VLD_OPT_VALIDATE_HEAPFREE       0x2000 //   If set, VLD verifies and reports heap consistency for HeapFree calls.
#define VLD_OPT_SKIP_CRTSTARTUP_LEAKS   0x4000 //   If set, VLD skip crt srtartup memory leaks.

3. 文件 vld.h 简介

这个文件里主要声明了 VLD 的 22 个外部接口。文件前面的编译条件 defined _DEBUG || defined VLD_FORCE_ENABLE 表明 VLD 通常只能在 DEBUG 模式下运行,若要在 RELEASE 模式下运行,可以在包含头文件 vld.h 前预先定义 VLD_FORCE_ENABLE 宏。一个有趣的现象是,这个 _DEBUG 宏有时候在 RELEASE 模式下也会被定义,参考文章 神秘的 _DEBUG 宏从何处来?。接口中的一些类型别名定义如下:

typedef int            VLD_BOOL;
typedef unsigned int   VLD_UINT;
typedef size_t         VLD_SIZET;
typedef void*          VLD_HMODULE;

3.1 接口 VLDDisable

该函数用于禁用当前线程的内存泄漏检测功能。

// VLDDisable - Disables Visual Leak Detector's memory leak detection at
//   runtime. If memory l
首页 上一页 1 2 3 4 5 6 7 下一页 尾页 1/7/7
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇数据结构基础—数组和广义表 下一篇网络框架重构之路plain2.0(c++23 ..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目