Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detecting the memory page size

Is there a portable way to detect (programmatically) the memory page size using C or C++ code ?

like image 843
Franck Freiburger Avatar asked Jul 28 '10 10:07

Franck Freiburger


People also ask

How do I find out the size of my memory page?

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.

What is page size in memory?

Pages are typically 512 to 8192 bytes, with 4096 being a typical value.

Why is page size 4KB?

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.


1 Answers

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;
}
like image 169
Ted Avatar answered Sep 29 '22 21:09

Ted