Why does the syscall getpagesize()
return an int
and not an unsigned int
or a size_t
?
Prototype and short description below:
GETPAGESIZE(2)
NAME
getpagesize - get memory page size
SYNOPSIS
#include <unistd.h>
int getpagesize(void);
The getpagesize() function returns the current page size. The getpagesize() function is equivalent to sysconf(_SC_PAGE_SIZE) and sysconf(_SC_PAGESIZE). Note: This function is kept for historical reasons.
Check it online There are online tools to check a web page's size. For example, you can do it using https://tools.pingdom.com. Type or paste in the URL of the page you want to check and there you go. You will get a lot of data, among which the size of the page.
int
was probably sufficient when it was invented. But it's no longer an issue because the
getpagesize()
has been removed from POSIX standard since 2001 and has been superseded by sysconf()
.
You should use 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.
(emphasis mine).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With