问题描述
我只是在摆弄内存映射,并想查看用户空间虚拟内存区域映射.像这样写了几行
I was just fiddling around memory mappings and wanted to view user space virtual memory region mappings. Wrote some lines like
char *ptr = NULL;
printf("Allocating 300KB\n");
ptr = malloc (300*1024);
printf("Allocated at %p.. sleeping\n", ptr);
sleep (30);
free (ptr);
printf("Freed... sleeping\n");
sleep (30);
在运行程序时,pid上的pmap
将分配的区域显示为:
On running the program, pmap
on the pid shows allocated region as:
00007f73b1e57000 316K rw--- [ anon ]
程序o/p说:
Allocated at 0x7f73b1e57010.. sleeping
这16KB的额外分配是我们所谓的分配魔术区域吗?在内核中,相应的vm_area_struct
将保存对程序可见的范围还是从魔术区域开始的整个范围?
Is this 16KB extra allocation for what we call magic region on allocation?In the kernel, the corresponding vm_area_struct
will hold ranges visible to program or the entire range from starting of magic region?
推荐答案
区别不是16KB,而是16个字节.哪个最可能对应于malloc必须在内存块之前分配的头,以便将块链接在一起,等等.
The difference is not 16KB, it is 16 bytes. Which most probably corresponds to the header that malloc has to allocate before your memory block so as to link blocks together, etc.
这篇关于malloc:匿名映射和魔术区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!