how to get Heap size of a program

前端 未结 6 651
太阳男子
太阳男子 2020-12-18 23:07

How to find heap memory size of a c++ program under linux platform ?I need heap memory space before the usage of new or malloc and also after that.can anyone help?

6条回答
  •  忘掉有多难
    2020-12-18 23:54

    On Linux you can read /proc/[pid]/statm to get memory usage information.

    Provides information about memory usage, measured in pages. The columns are:

                  size       total program size
                             (same as VmSize in /proc/[pid]/status)
                  resident   resident set size
                             (same as VmRSS in /proc/[pid]/status)
                  share      shared pages (from shared mappings)
                  text       text (code)
                  lib        library (unused in Linux 2.6)
                  data       data + stack
                  dt         dirty pages (unused in Linux 2.6)
    

    See the man page for more details.

    Answer by Adam Zalcman to this question describes some interesting details of the heap allocation

提交回复
热议问题