Reputation: 1890
#include <unistd.h>
(size_t) sysconf(_SC_PAGESIZE);
sysconf(_SC_PAGESIZE) tells me that my memory page size is 4096 on my operating system and processor. Of the 4096 bytes in the memory page, how many can be used for data and how much is overhead/metadata?
I have an application where I am optimizing cache locality by packing frequently accessed pointers into the same cache block and need to know if the whole memory page is usable, or if I will go over memory page boundaries by filling the whole memory page.
Upvotes: 2
Views: 216
Reputation: 16441
No metadata. 4096 bytes are usable.
The OS does store metadata somewhere, but it's on other pages, which shouldn't bother you.
Whether or not you can access memory, however, doesn't depend on the page size. If you have allocated 100 bytes, you can access just 100 bytes. If you have allocated 4096, you can access 4096.
Upvotes: 5