c - 为什么 getpagesize() 返回一个 int?

标签 c unix memory-management int system-calls

为什么系统调用 getpagesize() 返回 int 而不是 unsigned intsize_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/

相关文章:

java - Java 中不太像 Unix 的终端滚动

linux - 用于执行以下程序的 awk 或 shell 脚本

python 壳: pickle entire state

linux - 如何在 Linux 中处理多个 SIGSEGV 事件?

c - 删除第一个节点时无限循环

c - 使用套接字 API 的基于轮询的客户端服务器

c - 有什么办法可以运行 .exe 而不受到 Windows 的投诉吗?

c - -DNDEBUG 会干扰 -g 标志吗?

linux - 从 Ansible 中 shell 命令的输出中提取特定数据

c - Linux 堆结构和 malloc() 和 free() 的行为