valgrind包括了以下几个比较重要的模块:memcheck, cachegrind, callgrind, helgrind, drd, massif, dhat, sgcheck, bbv. 还有一些小工具,但不是每个人都能用上,比如Lackey, Nulgrind.

在linux系统下下载源程序之后,通过./configure, make, make install命令安装在系统中。

用法: $valgrind  [valgrind-options]  your-prog  [your-prog-options]

The most important option is --tool which dicates which valgrind tool to run. 默认情况下是 --tool==memcheck .

Memcheck is a memory error detector. 它能检测到C和C++程序中的下述问题:

1. 访问不该访问的内存  2. 使用未定义的变量  3. 堆内存的不正确释放,例如多次使用堆块,或者malloc/new/new[]与free/delete/delete[]的错配。

4. src和dst指针指向的内存区域存在重叠  5. passing a fishy ( possibly negative) value to the size parameter of a memory allocation function.  6. 内存泄露

如果使用malloc, calloc, realloc, valloc或者memalign, 必须以free释放

如果使用new分配内存,必须使用delete释放

如果使用new[]分配内存,必须以delete[]释放

each bit in the system has an associated V bit, which follows it around everywhere, even inside the CPU. it says whether or not the accompanying bit has a legitimate value.

Copying values around dose not cause Memcheck to check for, or report on , errors. However, when a value is used in a way which might conceivably affect your program's externally-visible behaviour, the associated V bits are immediately checked. If any of these indicate that the value is undefined (even partially), an error is reported.

这段话简单来说就是,每一bit的数据,都有一个伴随bit,称为 V(valid-value) bit. 它存储了这一bit数据是否合法(是否被定义)。只是简单复制数据,memcheck并不会检查和回报对应V bit的信息。但只用使用到的数据存在破坏程序的迹象,对应的V bits就会立即被检查,如过使用到的数据不合法,memcheck便会立即回报错误。例如一个数据被用作判断条件时,他对应的V bits就会被检查。

checks on defineness only occur in three places: when a value is used to generate a memory address, when control flow decision needs to be made, and when a system call is detected. Memcheck checks definedness of parameters as required.

Every bit in memory or in the CPU has an associated valid-value( V) bit. In addition, all bytes in memory, but not in the CPU, has an associated valid-address (A) bit. This indicates whether or not the program can legitimately read or write that location.

C++ 内存分析-valgrind的更多相关文章

  1. Qt Creator Valgrind内存分析前端(分析Nginx内存)

    Linux上使用Qt Creator进行C/C++开发http://my.oschina.net/eechen/blog/166969Qt Creator GDB调试前端(调试Nginx):http: ...

  2. valgrind massif内存分析[转]

    valgrind检查内存泄露 #valgrind   ./程序 内存泄漏问题,我们有memcheck工具来检查.很爽.但是有时候memcheck工具查了没泄漏,程序一跑,内存还是狂飙.这又是什么问题. ...

  3. Eclipse CDT Linux下内存分析 补记

    常用工具汇总 http://www.ibm.com/developerworks/cn/linux/l-cn-memleak/ 常用的内存分析工具 http://en.wikipedia.org/wi ...

  4. 各个函数消耗的时间profiling和内存泄漏valgrind

    来源:http://06110120wxc.blog.163.com/blog/static/37788161201333112445844/ ARM(hisi)上面的profiling和valgri ...

  5. mysql 与linux ~ 内存分析与调优

    一 简介:linux内存和mysql二 分类   1 用户空间和内核空间      用户空间内存,从低到高分别是五种不同的内存段      1 只读段 包含代码和常量等      2 数据段 包含全局 ...

  6. iOS app内存分析套路

    iOS app内存分析套路 Xcode下查看app内存使用情况有2中方法: Navigator导航栏中的Debug navigator中的Memory Instruments 一.Debug navi ...

  7. 【Android端 APP 内存分析】使用工具进行APP的内存分析

    Android端可以通过adb 命令直接获取内存信息,当然Android studio也提供了对内存的监控分析工具,并且后续可以结合MAT做分析 今天介绍的是通过Android studio和MAT工 ...

  8. Chrome开发者工具之JavaScript内存分析

    阅读目录 对象大小(Object sizes) 对象的占用总内存树 支配对象(Dominators) V8介绍 Chrome 任务管理器 通过DevTools Timeline来定位内存问题 内存回收 ...

  9. c中的进制与内存分析

    一. 进制 1. 什么是进制 l 是一种计数的方式,数值的表示形式 数一下方块的个数 汉字:十一   十进制:11  二进制:1011  八进制:13 l 多种进制:十进制.二进制.八进制.十六进制. ...

随机推荐

  1. 随机love'...

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 用ES6语法和方式写gulp

    安装依赖模块 npm i -g gulp npm i gulp babel-core babel-preset-es2015 --save-dev 在创建文件 .babelrc(文件名) : (文件内 ...

  3. 在Linux中设置自启动服务或程序

    三种方法: 1.基于linux的system V机制,其中有个运行级别和链接软连接指向服务脚本的机制. 服务脚本一般处于/etc/init.d/目录下, 而运行级别制定的默认执行脚本在/etc/rc. ...

  4. HTML,CSS,JS,JQ

    CSS: <style> <!--属性选择器--> .container input[type="text"][name="txt"]{ ...

  5. 跑github上的Symfony项目遇到的问题

    Loading composer repositories with package information Installing dependencies (including require-de ...

  6. Spring Security(16)——基于表达式的权限控制

    目录 1.1      通过表达式控制URL权限 1.2      通过表达式控制方法权限 1.2.1     使用@PreAuthorize和@PostAuthorize进行访问控制 1.2.2   ...

  7. bzoj3156防御准备

    3156: 防御准备 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 1349  Solved: 605[Submit][Status][Discuss ...

  8. 兼容不同浏览器的 CSS Hack 写法

    所谓 CSS Hack,是指在 CSS 代码中嵌入诸如 *,*html  等代码,方便于独立控制某种浏览器的具体样式.比如有些 CSS Hack 只能被 IE6 或 IE7 识别,而 Firefox ...

  9. 生成元(Digit Generator,ACM/ICPC Seoul 2005,UVa 1583)

    #include<cstdio>#include<cstdlib>#include<cstring>using namespace std;int t, n, a, ...

  10. drupal7 boost模块为登录用户提供缓存

    这段时间研究Drupal7的缓存相关,看了好多资料,都提到了boost和authcache两个模块,今天来说一下boost. 具体的下载安装,配置等,官网写的听清楚,boost模块地址 ,安装配置方法 ...