Sun Studio 12:使用 dbx 调试程序

利用内存使用检查

利用内存使用检查可了解所有使用中的堆内存。可以通过此信息大致了解程序中内存的分配位置或程序的哪些部分在使用动态性最强的内存。另外,在减少程序占用的动态内存时,此信息很有用,并且在进行性能优化时,此信息也可能有用。

内存使用检查在性能优化过程中或对控制虚拟内存使用很有用。程序退出时,便可生成内存使用报告。也可以在执行程序过程中,随时使用 showmemuse 命令(执行该命令会显示内存使用信息)来获得内存使用信息。有关信息,请参见showmemuse 命令

启用内存使用检查便同时启用了泄漏检查。除程序退出时的泄漏报告外,还会获得使用的块 (biu) 报告。缺省情况下,程序退出时会生成简短的使用的块报告。内存使用报告中的详细程度由 dbx 环境变量 rtc_biu_at_exit 控制(请参见设置 dbx 环境变量)。

以下是一个典型的简短内存使用报告。


Blocks in use report   (blocks in use: 5   total size:   40 bytes)

 Total     % of Num of  Avg     Allocation call stack
 Size       All Blocks  Size
========== ==== ====== ======  =====================================
        16  40%      2      8  nonleak < nonleak
         8  20%      1      8  nonleak < main
         8  20%      1      8  cyclic_leaks < main
         8  20%      1      8  cyclic_leaks < main

Blocks in use report   (blocks in use: 5   total size:   40 bytes)

Block in use (biu):
Found 2 blocks totaling 16 bytes (40.00% of total; avg block size 8)
At time of each allocation, the call stack was:
     [1] nonleak() at line 182 in "memuse.c"
     [2] nonleak() at line 185 in "memuse.c"

Block in use (biu):
Found block of size 8 bytes at address 0x21898 (20.00% of total)
At time of allocation, the call stack was:
     [1] nonleak() at line 182 in "memuse.c"
     [2] main() at line 74 in "memuse.c"

Block in use (biu):
Found block of size 8 bytes at address 0x21958 (20.00% of total)
At time of allocation, the call stack was:
     [1] cyclic_leaks() at line 154 in "memuse.c"
     [2] main() at line 118 in "memuse.c"

Block in use (biu):
Found block of size 8 bytes at address 0x21978 (20.00% of total)
At time of allocation, the call stack was:
     [1] cyclic_leaks() at line 155 in "memuse.c"
     [2] main() at line 118 in "memuse.c"
The following is the corresponding verbose memory use report:

可以随时使用 showmemuse 命令获得内存使用报告。