How to programmatically get the CPU cache page size in C++?
On Linux try the proccpuinfo library, an architecture independent C API for reading /proc/cpuinfo
On Win32, GetLogicalProcessorInformation
will give you back a SYSTEM_LOGICAL_PROCESSOR_INFORMATION
which contains a CACHE_DESCRIPTOR
, which has the information you need.
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:
- http://www.intel.com/Assets/PDF/appnote/241618.pdf
- http://softpixel.com/~cwright/programming/simd/cpuid.php