Equivalent of dwAllocationGranularity in Linux?

时光毁灭记忆、已成空白 提交于 2019-12-11 01:15:31

问题


What is the equivalent of dwAllocationGranularity in Linux? In Windows, it's defined as:

The granularity for the starting address at which virtual memory can be allocated.

Note that this is not the same thing as PAGE_SIZE, which is the granularity of a physical page.
(On Windows, the virtual address granularity is 64 KiB on x86, whereas the page size is of course 4 KiB.)


回答1:


The nearest equivalent of VirtualAlloc on Linux is mmap which, like VirtualAlloc, allows you to specify a desired allocation target address of the allocated memory. On Windows, this address must be aligned on the allocation granularity. On Linux, I quote from the mmap man page:

If addr is not NULL, then the kernel takes it as a hint about where to place the mapping; on Linux, the mapping will be created at a nearby page boundary.

As far as I know, there is no situation where the allocation granularity is higher than the page size of the system, so you should be able to safely use PAGE_SIZE as a substitute.



来源:https://stackoverflow.com/questions/24819212/equivalent-of-dwallocationgranularity-in-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!