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.

 

转载于:https://www.cnblogs.com/cbyzju/p/5453687.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值