Is there a portable way to detect (programmatically) the memory page size using C or C++ code ?
On Unix-like operating systems, the pagesiz command displays the size of a page of memory in bytes, as returned by getpagesize. On modern Linux systems, pagesize can be determined using the command getconf PAGESIZE or getconf PAGE_SIZE.
Pages are typically 512 to 8192 bytes, with 4096 being a typical value.
A 4 KB page size has been used for Virtual Memory since the sixties. In fact, today, the most common page size is still 4 KB. Choosing a page size is finding the middle ground between several factors. On the one hand, a smaller page will reduce fragmentation; thus saving memory space.
Windows 10, Visual Studio 2017, C++. Get the page size in bytes.
int main()
{
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
printf("%s %d\n\n", "PageSize[Bytes] :", sysInfo.dwPageSize);
getchar();
return 0;
}
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