linux中如何查看glibc内存分配情况

avatar
作者
猴君
阅读量:0

在Linux中,可以使用工具如malloc_infomtracevalgrindgdb等来查看glibc内存分配情况。

例如,可以使用mallinfo函数来查看glibc内存分配情况,示例代码如下:

#include  #include   int main() {     struct mallinfo mi = mallinfo();     printf("Total non-mmapped bytes (arena): %dn", mi.arena);     printf("# of free chunks (ordblks): %dn", mi.ordblks);     printf("# of fastbin blocks (smblks): %dn", mi.smblks);     printf("# of mmapped regions (hblks): %dn", mi.hblks);     printf("Space in mmapped regions (hblkhd): %dn", mi.hblkhd);     printf("Maximum total allocated space (usmblks): %dn", mi.usmblks);     printf("Free space (fsmblks): %dn", mi.fsmblks);     printf("Total allocated space (uordblks): %dn", mi.uordblks);     printf("Total free space (fordblks): %dn", mi.fordblks);     printf("Topmost releasable block (keepcost): %dn", mi.keepcost);          return 0; } 

编译并运行上述代码,即可查看glibc内存分配情况。

    广告一刻

    为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!