在Linux中相当于dwAllocationGranularity? [英] Equivalent of dwAllocationGranularity in Linux?

查看:225
本文介绍了在Linux中相当于dwAllocationGranularity?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

dwAllocationGranularity 在Linux中?在Windows中,其定义为:

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.

请注意,这与 PAGE_SIZE 不同 物理页面的粒度。

(在Windows上,虚拟地址粒度在x86上为64 KiB,而页面大小当然为4 KiB。)

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.)

推荐答案

Linux上与VirtualAlloc最接近的等效项是mmap,与VirtualAlloc一样,它允许您指定分配的内存的所需分配目标地址。在Windows上,此地址必须与分配粒度对齐。在Linux上,我从mmap手册页中引用:

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:


如果addr不为NULL,则内核将其用作提示位置。
放置映射;在Linux上,映射将在附近的
页面边界创建

据我所知,没有分配粒度大于系统页面大小的情况,因此您应该能够安全地使用PAGE_SIZE作为替代。

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.

这篇关于在Linux中相当于dwAllocationGranularity?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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