为什么系统调用 getpagesize()
返回 int
而不是 unsigned int
或 size_t
?
原型(prototype)和简短描述如下:
GETPAGESIZE(2)
NAME
getpagesize - get memory page size
SYNOPSIS
#include <unistd.h>
int getpagesize(void);
最佳答案
int
在发明时可能就足够了。但这不再是问题,因为
自 2001 年以来,getpagesize()
已从 POSIX 标准中删除,并已被 sysconf()
取代。
您应该使用 sysconf(_SC_PAGESIZE)
。
getpagesize()
returning an int was one of the major reasons why it was removed:
getpagesize
The getpagesize( ) function returns the current page size. It is equivalent to sysconf (_SC_PAGE_SIZE) and sysconf (_SC_PAGESIZE). This interface, returning an int, may have problems representing appropriate values in the future. Also the behaviour is not specified for this interface on systems that support variable size pages. On variable page size systems, a page can be extremely large (theoretically, up to the size of memory). This allows very efficient address translations for large segments of memory that have common page attributes. A note about this has been added to Application Usage, and the interface marked Legacy, with the recommendation that applications should use the sysconf() interface instead.
(强调我的)。
关于c - 为什么 getpagesize() 返回一个 int?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41890978/