getpagesize - get memory page size
getpagesize-获取内存页大小
所需头文件:
#include <unistd.h>
int getpagesize(void);
The function getpagesize() returns the number of bytes in a memory page, where "page" is a fixed-length block, the unit for memory allocation and file mapping performed by mmap(2).
getpagesize函数返回一个内存页所包含的字节数,“页”是一个固定长度的块,内存分配和mmap文件映射单元
提示:
Whether getpagesize() is present as a Linux system call depends on the architecture. If it is, it returns the kernel symbol PAGE_SIZE, whose value depends on the architecture and machine model. Generally, one uses binaries that are dependent on the architecture but not on the machine model, in order to have a single binary distribution per architecture. This means that a user program should not find PAGE_SIZE at compile time from a header file, but use an actual system call, at least for those architectures (like sun4) where this dependency exists. Here libc4, libc5, glibc 2.0 fail because their getpagesize() returns a statically derived value, and does not use a system call. Things are OK in glibc 2.1.
getpagesize是否作为一个system call实现取决与架构,如果实现了,那么返回kernel的PAGE_SIZE标志,这个值取决于架构和机器的类型,一般来说,为了使每个架构都有一个对应的库函数版本,库函数的使用依赖于架构而不是机器类型,这也就是说用户程序不要在编译期间通过头文件去获取PAGE_SIZE,而是用system call,尤其是在某些架构(例如sun4)这种依赖是存在的,这里libc4,libc5,glibc2.0会失败是因为他们的getpagesize()返回一个静态的引申值,而不是使用system call。直到glibc2.1上这个事情才算解决。
getpagesize-获取内存页大小
所需头文件:
#include <unistd.h>
int getpagesize(void);
The function getpagesize() returns the number of bytes in a memory page, where "page" is a fixed-length block, the unit for memory allocation and file mapping performed by mmap(2).
getpagesize函数返回一个内存页所包含的字节数,“页”是一个固定长度的块,内存分配和mmap文件映射单元
提示:
Whether getpagesize() is present as a Linux system call depends on the architecture. If it is, it returns the kernel symbol PAGE_SIZE, whose value depends on the architecture and machine model. Generally, one uses binaries that are dependent on the architecture but not on the machine model, in order to have a single binary distribution per architecture. This means that a user program should not find PAGE_SIZE at compile time from a header file, but use an actual system call, at least for those architectures (like sun4) where this dependency exists. Here libc4, libc5, glibc 2.0 fail because their getpagesize() returns a statically derived value, and does not use a system call. Things are OK in glibc 2.1.
getpagesize是否作为一个system call实现取决与架构,如果实现了,那么返回kernel的PAGE_SIZE标志,这个值取决于架构和机器的类型,一般来说,为了使每个架构都有一个对应的库函数版本,库函数的使用依赖于架构而不是机器类型,这也就是说用户程序不要在编译期间通过头文件去获取PAGE_SIZE,而是用system call,尤其是在某些架构(例如sun4)这种依赖是存在的,这里libc4,libc5,glibc2.0会失败是因为他们的getpagesize()返回一个静态的引申值,而不是使用system call。直到glibc2.1上这个事情才算解决。