C++ 内存分析-valgrind
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的更多相关文章
- Qt Creator Valgrind内存分析前端(分析Nginx内存)
Linux上使用Qt Creator进行C/C++开发http://my.oschina.net/eechen/blog/166969Qt Creator GDB调试前端(调试Nginx):http: ...
- valgrind massif内存分析[转]
valgrind检查内存泄露 #valgrind ./程序 内存泄漏问题,我们有memcheck工具来检查.很爽.但是有时候memcheck工具查了没泄漏,程序一跑,内存还是狂飙.这又是什么问题. ...
- Eclipse CDT Linux下内存分析 补记
常用工具汇总 http://www.ibm.com/developerworks/cn/linux/l-cn-memleak/ 常用的内存分析工具 http://en.wikipedia.org/wi ...
- 各个函数消耗的时间profiling和内存泄漏valgrind
来源:http://06110120wxc.blog.163.com/blog/static/37788161201333112445844/ ARM(hisi)上面的profiling和valgri ...
- mysql 与linux ~ 内存分析与调优
一 简介:linux内存和mysql二 分类 1 用户空间和内核空间 用户空间内存,从低到高分别是五种不同的内存段 1 只读段 包含代码和常量等 2 数据段 包含全局 ...
- iOS app内存分析套路
iOS app内存分析套路 Xcode下查看app内存使用情况有2中方法: Navigator导航栏中的Debug navigator中的Memory Instruments 一.Debug navi ...
- 【Android端 APP 内存分析】使用工具进行APP的内存分析
Android端可以通过adb 命令直接获取内存信息,当然Android studio也提供了对内存的监控分析工具,并且后续可以结合MAT做分析 今天介绍的是通过Android studio和MAT工 ...
- Chrome开发者工具之JavaScript内存分析
阅读目录 对象大小(Object sizes) 对象的占用总内存树 支配对象(Dominators) V8介绍 Chrome 任务管理器 通过DevTools Timeline来定位内存问题 内存回收 ...
- c中的进制与内存分析
一. 进制 1. 什么是进制 l 是一种计数的方式,数值的表示形式 数一下方块的个数 汉字:十一 十进制:11 二进制:1011 八进制:13 l 多种进制:十进制.二进制.八进制.十六进制. ...
随机推荐
- java方法笔记
1.方法 方法(method),函数(function)//但本质上是一样的--实现特定的功能.程序中完成独立功能,可重复使用的一段代码的集合:方法的格式:[修饰符] 返回值的类型 方法名称([形式参 ...
- jQuery datepicker和jQuery validator 共用时bug
当我们给一个元素绑定一个datepick后又要对它用validator进行验证时会发现验证并没有成功 因为当点击该元素时候input弹出datepick的UI就已经失去了焦点它验证的仍然是前一个值, ...
- Ubuntu环境openresty的安装
Ubuntu环境openresty的安装 相关库的安装 安装openresty需要的库 apt-get install libreadline-dev libncurses5-dev libpcre ...
- svn恢复到某一版本
转 经常由于坑爹的需求,功能要切回到之前的某一个版本.有两种方法可以实现: 方法1: 用svn merge 1) 先 svn up,保证更新到最新的版本,如20: 2) 然后用 svn log ,查看 ...
- gimagex 2.0.17 汉化版
软件名称: gimagex 2.0.17 汉化版 软件语言: 简体中文 授权方式: 免费软件 运行环境: Win 32位/64位 软件大小: 1.31MB 图片预览: 软件简介: gimagex 2. ...
- scrapy 抓取动态网页
-- coding: utf-8 -- ''' gouwu.sogou.com Spider, Created on Dec, 2014 version: 1.0 author: chenqx @ht ...
- Python学习笔记——基础篇【第六周】——PyYAML & configparser模块
PyYAML模块 Python也可以很容易的处理ymal文档格式,只不过需要安装一个模块,参考文档:http://pyyaml.org/wiki/PyYAMLDocumentation 常用模块之Co ...
- Python基础知识学习_Day2
一.for循环 1.1功能及语法 for循环是迭代循环机制(while是条件循环),语法如下: for i in a b c: print(i) 1.2典型例子: 1.2.1猜年龄循环 realy_a ...
- iOS 隐藏导航栏 隐藏状态栏
1导航栏 self.navigationController.navigationBarHidden = YES; 2 状态栏 [[UIApplication sharedApplication] s ...
- Linux kernel Vhost-net 和 Virtio-net代码详解
场景 Host上运行qemu kvm虚拟机,其中虚拟机的网卡类型为virtio-net,而Host上virtio-net backend使用vhost-net 数据包进入虚拟机代码分析 首先看vhos ...