使用内存使用检查,您可以查看所有使用的堆内存。可以通过此信息大致了解程序中内存的分配位置或程序的哪些部分在使用动态性最强的内存。另外,在减少程序占用的动态内存时,此信息很有用,并且在进行性能优化时,此信息也可能有用。
内存使用检查在性能优化过程中或对控制虚拟内存使用很有用。程序退出时,便可生成内存使用报告。您也可以使用 showmemuse 命令在程序执行期间随时获取内存使用情况信息,该命令可显示内存使用情况。 有关信息,请参见showmemuse 命令。
启用内存使用检查时,也会启用泄露检查。除了程序退出时的泄漏报告外,您还将获得一份使用的块 (biu) 报告。缺省情况下,系统会在程序退出时生成非详细的使用的块报告。内存使用报告中的详细程度由 dbxenv 变量 rtc_biu_at_exit 控制。
以下示例显示了典型的非详细内存使用报告。
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 命令获得内存使用报告。