Determining the Page Size

Most operating systems allow programs to determine what the page size is so that they can allocate memory more efficiently.

UNIX and POSIX-based Operating Systems

UNIX and POSIX-based systems use the C function sysconf().

Edit a test.c file and paste it:

  #include <stdio.h>     // printf(3)
#include <unistd.h>    // sysconf(3)

int
main(void)
{
        printf("The page size for this system is %ld bytes\n", sysconf(_SC_PAGESIZE)); //_SC_PAGE_SIZE is OK too.
        return 0;
}
  

Then compile it with gcc:

  gcc -o test test.c
  

Now launch it:

  # ./test
The page size for this system is 4096 bytes
  

Win32-based Operating Systems (Windows 9x, NT, ReactOS)

Win32-based operating system use the C function GetSystemInfo() function in kernel32.dll

  #include <windows.h>

SYSTEM_INFO si;

GetSystemInfo(&si);
printf("The page size for this system is %u bytes\n", si.dwPageSize);
  

Last updated 09 May 2007, 13:11 CEST. history