简体   繁体   English

高内存范围内的堆分配地址

[英]heap allocating address in the high memory range

I am facing this strange issue in which the addresses malloc 'ed between two calls to malloc differ a lot in terms of the address allocated, for example: 我面临着一个奇怪的问题,即两次调用malloc之间的地址malloc在分配的地址方面有很大不同,例如:

iovec = 0x6201f0

and: 和:

iovec = 0x7ffff00008e0

and the size of the iovec structure is 40 bytes. iovec结构的大小为40个字节。 Is there a possible reason to explain this behavior ? 是否有可能解释这种现象?

Whatever the address, it should not be an issue. 无论地址是什么,都不应该成为问题。 One potential reason is that there are two different routes for the dynamic memory system to get memory from the system. 一个潜在的原因是动态内存系统从系统获取内存有两种不同的途径。 One is brk() and the other anonymous (ie MAP_ANON ) mmap() . 一个是brk() ,另一个是匿名(即MAP_ANONmmap() I believe glibc uses brk() for small amounts of memory but mmap() for large. 我相信glibc使用brk()来存储少量内存,而使用mmap()来存储大量内存。 If you have an intervening call to allocate a large amount of memory, the subsequent malloc() for a 40 byte iovec may sit in the end of the page(s) grabbed using mmap() . 如果您有一个调用来分配大量内存,则40字节iovec的后续malloc()可能位于使用mmap()抓取的页面的末尾。 If you really want to know what's happening, I suggest you use strace and find out the memory addresses returned. 如果您真的想知道发生了什么,建议您使用strace并找出返回的内存地址。

Also note that if you allocated one on the stack rather than the heap, then it will (of course) have a different looking memory address. 还要注意,如果您在堆栈而不是堆上分配了一个,那么它(当然)将具有不同的外观内存地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM