gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 15:19:16 29 4
gpt4 key购买 nike

为什么系统调用 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com