- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
size_t sz = atol(argv[1]);
char *arr = malloc(sz);
sleep(10);
}
我编译了这段代码并尝试运行它,使用
pmap
查看了程序的内存映射。
1024000
这样的大数字时,我得到了这样的映射:
3901: ./alloc_program 1024000
0000560192f43000 4K r---- alloc_program
0000560192f44000 4K r-x-- alloc_program
0000560192f45000 4K r---- alloc_program
0000560192f46000 4K r---- alloc_program
0000560192f47000 4K rw--- alloc_program
0000560192fac000 132K rw--- [ anon ]
00007f75b69e9000 1004K rw--- [ anon ] <---- I believe this is the allocated memory
00007f75b6ae4000 148K r---- libc-2.31.so
00007f75b6b09000 1504K r-x-- libc-2.31.so
00007f75b6c81000 296K r---- libc-2.31.so
00007f75b6ccb000 4K ----- libc-2.31.so
00007f75b6ccc000 12K r---- libc-2.31.so
00007f75b6ccf000 12K rw--- libc-2.31.so
00007f75b6cd2000 24K rw--- [ anon ]
00007f75b6ce7000 4K r---- ld-2.31.so
00007f75b6ce8000 140K r-x-- ld-2.31.so
00007f75b6d0b000 32K r---- ld-2.31.so
00007f75b6d14000 4K r---- ld-2.31.so
00007f75b6d15000 4K rw--- ld-2.31.so
00007f75b6d16000 4K rw--- [ anon ]
00007ffe2b26e000 132K rw--- [ stack ]
00007ffe2b318000 12K r---- [ anon ]
00007ffe2b31b000 4K r-x-- [ anon ]
ffffffffff600000 4K --x-- [ anon ]
total 3496K
我想标记的行是由malloc分配的内存(也许我错了)。
10240
这样的小数字时,我看不到分配了什么:
3879: ./alloc_program 10240
000055e428e26000 4K r---- alloc_program
000055e428e27000 4K r-x-- alloc_program
000055e428e28000 4K r---- alloc_program
000055e428e29000 4K r---- alloc_program
000055e428e2a000 4K rw--- alloc_program
000055e42a257000 132K rw--- [ anon ]
00007f102332c000 148K r---- libc-2.31.so
00007f1023351000 1504K r-x-- libc-2.31.so
00007f10234c9000 296K r---- libc-2.31.so
00007f1023513000 4K ----- libc-2.31.so
00007f1023514000 12K r---- libc-2.31.so
00007f1023517000 12K rw--- libc-2.31.so
00007f102351a000 24K rw--- [ anon ]
00007f102352f000 4K r---- ld-2.31.so
00007f1023530000 140K r-x-- ld-2.31.so
00007f1023553000 32K r---- ld-2.31.so
00007f102355c000 4K r---- ld-2.31.so
00007f102355d000 4K rw--- ld-2.31.so
00007f102355e000 4K rw--- [ anon ]
00007fff1d513000 132K rw--- [ stack ]
00007fff1d570000 12K r---- [ anon ]
00007fff1d573000 4K r-x-- [ anon ]
ffffffffff600000 4K --x-- [ anon ]
total 2492K
1-为什么当内存较小时它不分配?
1004KB
,而我仅分配了
1000KB
。
最佳答案
1 - Why it doesn't allocate when the memory size is relatively small?
malloc
函数的任务是在需要时为应用程序提供内存。从理论上讲,
malloc
可以按照您的建议将所有内存分配请求转发到操作系统的
kernel,以便它仅充当内核内存分配器的包装器。但是,这具有以下缺点:
malloc
不直接将内存分配请求直接转发到内核,而是充当应用程序的内存分配请求和内核之间的中介,效率更高。它从内核请求大量内存,因此它可以满足来自应用程序的许多较小的内存分配请求。
malloc
才会将该内存分配请求转发给内核。
2 - Why the allocated memory size is not exactly the same? In the first run, it shows that the size is
1004KB
while I've only allocated1000KB
.
malloc
分配器必须跟踪它授予应用程序的所有内存分配,还必须跟踪内核已授予它的所有内存分配。要存储此信息,它需要一点额外的存储空间。此额外空间称为“开销”。
关于c - 为什么malloc在达到一定阈值之前不分配内存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63211326/
我正在用 R 编写程序。我卡在这里。 我有像这样的矢量 X=c(84.05, 108.04, 13.95, -194.05, 64.03, 208.05, 84.13, 57.04) 我想在用 180
我正在编写一个应用程序,该应用程序涉及使用手指或手写笔在屏幕上书写。我有那部分工作。在 ACTION_DOWN 上,开始绘制;在 ACTION_MOVE 上,添加线段;在 ACTION_UP 上,完成
我正在尝试构建 OCR 以从图像中提取文本,我正在使用轮廓来形成文本字符的边界, 经过几次更改 cv2.threshold 的试验后,我在形成文本字符的边界时得到了最适合的轮廓。 #files = o
我正在尝试使用 OpenCV 的 cv::threshold函数(更具体 THRESH_OTSU ),只是我想用蒙版(任何形状)来做,以便在计算过程中忽略外部(背景)。 图像是单 channel (必
对于学校项目,我试图用 Python 编写一个程序来跟踪学生的运动。为了做到这一点,我正在使用 OpenCV。 在互联网上查找了一些教程后,我注意到几乎每个人都使用阈值来实现这一点,因为几乎每一步都需
我使用 jest 来驱动 selenium 测试,它报告一个需要 12 秒的测试缓慢(持续时间以红色突出显示)。在这种情况下,12 秒就可以了。 如何将阈值配置为 30 秒? 最佳答案 Jest is
我想找到 list1 中与 list2 中的值足够接近的值(基于指定的阈值),即与下面的代码类似的功能。然而,与 pyhton 的 set 交集相比,下面的 intersect_with_thresh
我正在尝试创建一张图表上有两个系列并带有阈值选项的浮线图。我知道当我只有 1 个系列时如何启用阈值(就像这里 http://people.iola.dk/olau/flot/examples/thre
我已正确应用 d3 (v 4.0) 直方图函数对数据数组进行分箱。我的代码如下所示: var bins = d3.histogram() .domain([data_points_min,
我正在使用带有自然语言全文的 Mysql FULLTEXT 搜索,不幸的是,我遇到了 FULLTEXT 50% 阈值,如果给定的关键字出现在总行数的 50% 时间,则不允许我搜索行。 我搜索并找到了一
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 8 年前。 Improve th
这是我的绘图数据 var data = [{ data: [[4, 80], [8, 50], [9, 130]], color: "r
是否可以制作Canny忽略短边还是忽略低梯度边?在我的例子中,我将卡片放在木头上,并在 canny 之后看到木结构的许多边缘 canny 函数中的两个阈值有什么用? 最佳答案 Large intens
我正在尝试使用 OpenCV 的 cv::threshold 函数(更具体的 THRESH_OTSU),只是我想使用掩码(任何形状) ), 以便在计算过程中忽略外部(背景)。 图像是单 channel
我正在寻找根据提供的音频、频率范围(例如 20hz-1000hz)和阈值缩放 PNG 文件,以获得平滑的效果。 例如,当有脚踢时,比例平滑到 120%,我想让那些音频可视化器,如 dubstep 等.
我正在尝试找到最佳阈值,以使我的逻辑回归具有最高的 f1 分数。但是,当我写下以下几行时: val f1Score = metrics.fMeasureByThreshold f1Score.fore
我使用 Flot 创建了一个实时(每 10 毫秒更新一次)垂直样条图。图表可见here on Codepen 。我包括了 Flot multiple threshold plugin ,但我希望阈值使
我有一个数据框,其中包含从第 1 天到第 7 天的三个人(John、Terry、Henry)的分数。 1 2 3 4 5 6 7
我正在尝试实现多级 Otsu 阈值,更具体地说,我需要 3 个阈值/4 个类。 我知道关于 SO 的 2 个类似问题:#34856019 和 #22706742。问题是我没有得到好的结果:我已经阅读了
The documentation在 THRESH_BINARY 上说: dst(x,y) = maxval if src(x,y) > thresh else 0 这对我来说并不意味着这不适用于彩色
我是一名优秀的程序员,十分优秀!