- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在研究调试 fork TCP 服务器中的内存使用情况。我认为我做得很好,我只是似乎无法在“堆摘要”中找到有关“分配的字节数”的信息。我的服务器运行时间越长,这个数字似乎就会不断增加:
==27526==
==27526== HEAP SUMMARY:
==27526== in use at exit: 0 bytes in 0 blocks
==27526== total heap usage: 113 allocs, 113 frees, 283,043 bytes allocated
==27526==
==27526== All heap blocks were freed -- no leaks are possible
==27526==
==27526== For counts of detected and suppressed errors, rerun with: -v
==27526== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)
==27528==
==27528== HEAP SUMMARY:
==27528== in use at exit: 0 bytes in 0 blocks
==27528== total heap usage: 120 allocs, 120 frees, 300,808 bytes allocated
==27528==
==27528== All heap blocks were freed -- no leaks are possible
==27528==
==27528== For counts of detected and suppressed errors, rerun with: -v
==27528== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)
==27537==
==27537== HEAP SUMMARY:
==27537== in use at exit: 0 bytes in 0 blocks
==27537== total heap usage: 127 allocs, 127 frees, 318,573 bytes allocated
==27537==
==27537== All heap blocks were freed -- no leaks are possible
==27537==
==27537== For counts of detected and suppressed errors, rerun with: -v
==27537== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)
虽然 Valgrind 报告分配和释放是相等的并且不可能发生泄漏,但我不相信分配的字节会增加。
那么:如果分配的字节不断增加,这是否意味着即使 Valgrind 报告不可能发生泄漏,我也必须从堆中的某个地方取消分配?
谢谢!
编辑:有了戈登·贝利的回答和其他提示,我仍然有点疲倦。写了这个小应用程序:
/* client.c */
#include <stdio.h>
void child_func(int childnum);
int main(int argc, char *argv[])
{
int nchildren = 1;
int pid;
int x;
if (argc > 1)
{
nchildren = atoi(argv[1]);
}
for (x = 0; x < nchildren; x++)
{
if ((pid = fork()) == 0)
{
child_func(x + 1);
exit(0);
}
}
wait(NULL);
return 0;
}
void child_func(int childnum)
{
int i;
for (i = 0; i < 1000; i++) {
free(malloc(1));
}
sleep(1);
}
当我运行此命令时,Valgrind 输出为:
==28245== HEAP SUMMARY:
==28245== in use at exit: 0 bytes in 0 blocks
==28245== total heap usage: 1,000 allocs, 1,000 frees, 1,000 bytes allocated
==28245==
==28245== All heap blocks were freed -- no leaks are possible
==28245==
==28245== For counts of detected and suppressed errors, rerun with: -v
==28245== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)
==28246== HEAP SUMMARY:
==28246== in use at exit: 0 bytes in 0 blocks
==28246== total heap usage: 1,000 allocs, 1,000 frees, 1,000 bytes allocated
==28246==
==28246== All heap blocks were freed -- no leaks are possible
所以看起来堆上的所有内存都被清除了,并且与我的应用程序的输出肯定不同。
最佳答案
Valgrind 的分配的字节
是您在进程运行时分配的字节总数。
如果你编译并运行这个奇怪的小测试程序:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for(i = 0; i < 1000; ++i){
free(malloc(1));
}
return 0;
}
Valgrind 的输出是:
==2651== Memcheck, a memory error detector
==2651== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==2651== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info
==2651== Command: ./test_prog
==2651==
==2651==
==2651== HEAP SUMMARY:
==2651== in use at exit: 0 bytes in 0 blocks
==2651== total heap usage: 1,000 allocs, 1,000 frees, 1,000 bytes allocated
==2651==
==2651== All heap blocks were freed -- no leaks are possible
==2651==
==2651== For counts of detected and suppressed errors, rerun with: -v
==2651== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 13 from 8)
现在看来真正的问题是子进程如何影响这一点。
(编辑以确认我的想法)
关于c - Valgrind 了解堆摘要中分配的字节数增加吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11730265/
我需要从 1024 增加 FD_SETSIZE 值至 4096 .我知道最好使用 poll()/epoll()但我想了解什么是优点/缺点。主要问题是:我要重新编译glibc吗? ?我读了几个线程,其中
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
我在 HTML 文件中有这样的内容: var value = 0; add(x){ x++; do
有没有办法在用户向上滚动时增加变量,并在用户使用 JavaScript 向下滚动时减少变量?变量没有最大值或最小值,如果能够调整灵敏度就好了。我不知道从哪里开始,感谢您的帮助! 编辑:没有滚动条,因为
我是 ios 新手,遇到以下问题。 我想根据表格 View 中元素的数量增加和减少表格 View 的高度大小。如果在输入时客户端在输出时给出 3 个或超过 3 个元素,我希望看到一个比默认行大 2 行
所以我一直在四处搜索,似乎大多数人认为以下列方式递增 indexPath 是正确的方法: NSIndexPath *newIndexPath = [NSIndexPath indexPathForRo
我有一个关于 connSupervisionTimeout 的问题。 我正在使用 CoreBluetooth 编写应用程序。我检查了连接参数和 connSupervisionTimeout = 720
我正在尝试根据页面的滚动位置更改元素的填充;当用户向下滚动页面时,填充会增加,而当他们向上滚动时,填充会减少。 我的主要问题是滚动不是很流畅,有时如果我滚动到页面顶部太快,每次元素的填充大小都不一样。
我正在尝试计算 18456 个基因的相关性度量,但编译器 (Dev C) 在将宏 GENE 或 INDEX 增加到 4000 到 5000 之间的值后退出或大。例如,它适用于: # define GE
我有一个带有 position: absolute 和 CSS3 过渡的圆形元素(a 元素)。在 hover 事件中,我想增加圆的高度和宽度,但我想在所有边上添加像素,而不仅仅是在左侧或右侧。 示例如
为了改善用户体验,我计划在我网站的所有页面(A-、A、A+)上增加/减少/重置字体大小 我面临的问题是页面上不同元素使用的字体大小不统一。有些是 14px,有些是 18px,有些是 12px,有些是
本文实例讲述了Yii框架数据库查询、增加、删除操作。分享给大家供大家参考,具体如下: Yii 数据库查询 模型代码: ?
sql替换语句,用该命令可以整批替换某字段的内容,也可以批量在原字段内容上加上或去掉字符。 命令总解:update 表的名称 set 此表要替换的字段名=REPLACE(此表要替换的字段名, '原
sql不常用函数总结以及事务,增加,删除触发器 distinct 删除重复行 declare @x 申明一个变量 convert(varchar(20),t
要增加我使用的最大可用内存: export SPARK_MEM=1 g 或者我可以使用 val conf = new SparkConf() .setMaster("loca
我正在尝试将文本(自定义文本按钮)放入 AppBar 的前导属性中。但是,当文本太长时,文本会变成多行 Scaffold( appBar: AppBar( centerTi
我正在使用最新版本的 NetBeans,我需要增加输出和菜单的字体大小(不是代码部分)。我试过: netbeans_default_options=".... --fontsize 16" 但是当我将
我必须将 180000 个点绘制到一个 EPS 文件中。 使用标准 gnuplot 输出尺寸点彼此太接近,这使得它们无法区分。有没有办法增加图像的宽度和高度? 最佳答案 是的。 set termina
我有一个带有输入字段的 twitter bootstrap 3 导航栏。我想增加输入字段的宽度。我已尝试设置 col 大小,但它不起作用。 html比较长,请引用bootply http://www.
我正在尝试增加 ggplot 标题中下划线的大小/宽度/厚度。我曾尝试使用大小、宽度和长度,但没有成功。 这是我所做的一个例子。 test <- tibble(x = 1:5, y = 1, z =
我是一名优秀的程序员,十分优秀!