已用内存(以字节为单位)。 Linux 堆块大小

发布于 2024-10-30 19:58:16 字数 384 浏览 3 评论 0 原文

我正在使用 valgrind 来了解我的 Linux 应用程序正在使用多少字节。 因此,Valgrind 摘要显示了已使用的堆块数量。因此,我想知道这些块的大小是多少,以了解堆的大小。

这里是 Valgrind 的堆摘要:

==2604== HEAP SUMMARY:
==2604==     in use at exit: 4,828,441 bytes in 1,416 blocks
==2604==   total heap usage: 389,448,458 allocs, 389,447,042 frees, 4,664,484,349 bytes allocated
==2604== 

我不能简单地执行块/字节,因为最后一个块不一定全部分配。 谢谢

I'm using the valgrind to know how many bytes my linux application is using.
So, the Valgrind summary show me the number of heap block used. Thus, i'd like to know what is the size of these blocks to know the size of the heap.

here the Heap Summary of the Valgrind:

==2604== HEAP SUMMARY:
==2604==     in use at exit: 4,828,441 bytes in 1,416 blocks
==2604==   total heap usage: 389,448,458 allocs, 389,447,042 frees, 4,664,484,349 bytes allocated
==2604== 

I can't simply do block/bytes because the last block isn't necessarily all allocated.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橘和柠 2024-11-06 19:58:17

在大多数机器上(我很确定所有 i386 和 x86_64 机器)内存都是以 4096 字节块来管理的。

On most machines (I'm pretty sure all i386 and x86_64 machines) memory is managed in 4096 byte blocks.

π浅易 2024-11-06 19:58:16

添加选项 --leak-check=fullvalgrind 将按调用堆栈显示块的详细摘要。如果块仍然可达,您可能还需要添加 --show-reachable=yes。从那里,您可以使用一些简单的数学来了解每种类型块的平均大小。

==15210== 46,622 bytes in 1,626 blocks are still reachable in loss record 2 of 3
==15210==    at 0x4022724: malloc (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==15210==    by 0x80562A1: (within /bin/ls)
==15210==    by 0x80563D1: (within /bin/ls)
==15210==    by 0x8053B84: (within /bin/ls)
==15210==    by 0x804F686: (within /bin/ls)
==15210==    by 0x804FAEB: (within /bin/ls)
==15210==    by 0x406F02B: (below main) (in /lib/libc-2.6.1.so)
==15210==

上面是平均大小的块:

$ echo $((46622/1626))
28

Add the option --leak-check=full and valgrind will show a detailed summary of blocks by call-stack. You may need to add also --show-reachable=yes if the blocks are still reachable. From there, you can use some simply math to know the average size of each type of block.

==15210== 46,622 bytes in 1,626 blocks are still reachable in loss record 2 of 3
==15210==    at 0x4022724: malloc (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==15210==    by 0x80562A1: (within /bin/ls)
==15210==    by 0x80563D1: (within /bin/ls)
==15210==    by 0x8053B84: (within /bin/ls)
==15210==    by 0x804F686: (within /bin/ls)
==15210==    by 0x804FAEB: (within /bin/ls)
==15210==    by 0x406F02B: (below main) (in /lib/libc-2.6.1.so)
==15210==

That above are blocks of average size:

$ echo $((46622/1626))
28
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文