c++ccachingoperating-systemsystems-programming

Programmatically get the cache line size?


All platforms welcome, please specify the platform for your answer.

A similar question: How to programmatically get the CPU cache page size in C++?


Solution

  • You can use std::hardware_destructive_interference_size since C++17.
    Its defined as:

    Minimum offset between two objects to avoid false sharing. Guaranteed to be at least alignof(std::max_align_t)