ein*_*ica 5 linux malloc memory-management
在Linux上,我们有一个名为mallinfo的(GNU C库)函数,它为您提供了一些与内存分配相关的数字:
struct mallinfo {
int arena; /* Non-mmapped space allocated (bytes) */
int ordblks; /* Number of free chunks */
int smblks; /* Number of free fastbin blocks */
int hblks; /* Number of mmapped regions */
int hblkhd; /* Space allocated in mmapped regions (bytes) */
int usmblks; /* Maximum total allocated space (bytes) */
int fsmblks; /* Space in freed fastbin blocks (bytes) */
int uordblks; /* Total allocated space (bytes) */
int fordblks; /* Total free space (bytes) */
int keepcost; /* Top-most, releasable space (bytes) */
};
Run Code Online (Sandbox Code Playgroud)
奇怪的是,这些值通常是32位整数(!); 好吧,那真的不会做,特别是对于以字节数给出的值(例如fordblks).
我猜这是以某种方式被弃用,并且其他一些设施可用于获取相同的信息.什么是替代设施?
使用 malloc_info()。您需要解析它的 xml 输出。
从malloc_info 手册页:
malloc_info() 函数旨在解决 malloc_stats(3) 和 mallinfo(3) 中的缺陷。
例如,可以在此处获取 malloc_info 的源代码。所有变量都相应地使用size_t和打印出来,它应该在任何位机器上工作。
例如,在我的系统(glibc 版本 2.26)上malloc_info(0, stdout)打印出以下内容:
<malloc version="1">
<heap nr="0">
<sizes>
</sizes>
<total type="fast" count="0" size="0"/>
<total type="rest" count="0" size="0"/>
<system type="current" size="135168"/>
<system type="max" size="135168"/>
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</heap>
<total type="fast" count="0" size="0"/>
<total type="rest" count="0" size="0"/>
<total type="mmap" count="0" size="0"/>
<system type="current" size="135168"/>
<system type="max" size="135168"/>
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</malloc>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
497 次 |
| 最近记录: |