I'd like my program to read the cache line size of the CPU it's running on in C++.
I know that this can't be done portably, so I will need a solution for Linux and another for Windows (Solutions for other systems could be usefull to others, so post them if you know them).
For Linux I could read the content of /proc/cpuinfo and parse the line begining with cache_alignment. Maybe there is a better way involving a call to an API.
For Windows I simply have no idea.
Right-click on the Start button and click on Task Manager. 2. On the Task Manager screen, click on the Performance tab > click on CPU in the left pane. In the right-pane, you will see L1, L2 and L3 Cache sizes listed under “Virtualization” section.
There are 4 cores reported, then the total size of L1 cache = 4 X 64 KB = 256 KB.
The cache line is generally fixed in size, typically ranging from 16 to 256 bytes. The effectiveness of the line size depends on the application, and cache circuits may be configurable to a different line size by the system designer.
On Win32, GetLogicalProcessorInformation
will give you back a SYSTEM_LOGICAL_PROCESSOR_INFORMATION
which contains a CACHE_DESCRIPTOR
, which has the information you need.
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