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 多种进制:十进制.二进制.八进制.十六进制. ...
随机推荐
- MIPS指令集
MIPS 指令集(共31条) 助记符 指令格式 示例 示例含义 操作及其解释 Bit # 31..26 25..21 20..16 15..11 10..6 5..0 R-type op rs rt ...
- AngularJSLiveLessons
https://www.youtube.com/watch?v=8P4K6NCFtJ8&feature=youtu.be&list=PLzpMMGE0rxPkenSURlthkctgK ...
- 端口(port)的安全模式(security mode)
1. Cisco29系列交换机可以做基于2层的端口安全 ,即mac地址与端口进行绑定.2. Cisco3550以上交换机均可做基于2层和3层的端口安全, 即mac地址与端口绑定以及mac地址与ip地址 ...
- WPS Office 二次开发简易教程。
http://bbs.wps.cn/forum.php?mod=viewthread&tid=22004642
- 开发中常用的 $.extend 总结
工作中常见$.extend( ),所以就查了一些它的用法. 一.Jquery的扩展方法原型是: extend(dest, src1, src2, src3...) 它的含义是将src1,src2,sr ...
- NEUQ1051: 谭浩强C语言(第三版)习题6.7
//C代码简直难看到家,求大神知道如何写出复用性好的,维护性强的代码... //格式错误了好几次,最后发现是are和数字之间多了个空格......本来一直以为是最后的换行多了,费劲搞掉了. #incl ...
- abowman
http://abowman.com/google-modules/ball-clock/
- HDU 4451 Dressing
HDU 4451 Dressing 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=4451 Description Wangpeng has ...
- 为OLED屏增加GUI支持
为OLED屏增加GUI支持1:OLED驱动 为OLED屏增加GUI支持2:2D图形库 为OLED屏增加GUI支持3:字库 为OLED屏增加GUI支持4:文本框控件 为OLED屏增加GUI支持5:图片控 ...
- 安装aptana(1)
以前在myeclipse8.5上装了aptana,现在用myeclipse2014了,但是用原来的方法没有安装上,网上搜了下,发现都是老的方法,对新版的myeclipse已经不适用了,下面是转载的一篇 ...