how to get Heap size of a program

如何在Linux平台下查找c ++程序的堆内存大小?在使用new或malloc之前以及之后需要堆内存空间。任何人都可以帮忙?

#include <malloc.h>
#include <iostream>
int main()
{

     //here need heap memory space
     unsigned char* I2C_Read_Data= new unsigned char[250];
     //get heap memory space After the usage of new 
     return 0;
 }

使用valgrind的堆分析器:Massif


You can also add heap tracking to your own programs by overloading the new and delete operators. In a game engine I am working on, I have all memory allocation going through special functions, which attach each allocation to a particular heap tracker object. This way, at any given moment, I can pull up a report and see how much memory is being taken up by entities, actors, Lua scripts, etc.

It's not as thorough as using an external profiler (particularly when outside libraries handle their own memory management), but it is very nice for seeing exactly what memory you were responsible for.

我的记忆表的样本


You can use the getrlimit function call and pass the RLIMIT_DATA for the resource. That should give you the size of the data segment for your program.

链接地址: http://www.djcxy.com/p/86510.html

上一篇: 当您在unix系统上调用malloc()时会发生什么情况

下一篇: 如何获得程序的堆大小