How to programmatically get the CPU cache page size in C++? How to programmatically get the CPU cache page size in C++? linux linux

How to programmatically get the CPU cache page size in C++?


On Win32, GetLogicalProcessorInformation will give you back a SYSTEM_LOGICAL_PROCESSOR_INFORMATION which contains a CACHE_DESCRIPTOR, which has the information you need.


On Linux try the proccpuinfo library, an architecture independent C API for reading /proc/cpuinfo


For x86, the CPUID instruction. A quick google search reveals some libraries for win32 and c++. I have used CPUID via inline assembler as well.

Some more info: