malloc:匿名映射和魔术区域 [英] malloc : Anonymous mapping and magic area

查看:110
本文介绍了malloc:匿名映射和魔术区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在摆弄内存映射,并想查看用户空间虚拟内存区域映射.像这样写了几行

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:匿名映射和魔术区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆