Do you expect a certain guaranteed behavior, e.g. that the cache line is never loaded, if the object is not accessed, etc.? Or certain behavior for multiple cores?

 

Or is it just a performance hint? And could be ignored and be still a correct program?
 

-----Ursprüngliche Nachricht-----
Von: Frederick Virchanza Gotham via Std-Proposals <std-proposals@lists.isocpp.org>
Gesendet: Mi 01.04.2026 13:49
Betreff: [std-proposals] std::cache_isolated
An: std-proposals <std-proposals@lists.isocpp.org>;
CC: Frederick Virchanza Gotham <cauldwell.thomas@gmail.com>;
 
I wasn't sure if this would be something for Boost, but then I was thinking that the compiler writers would know more about the target architecture. So maybe it belongs in the C++ standard library rather than Boost.

If we had a wrapper class to force at most one object to a cache line, the most naive implementation could be something like:

template<typename T>
class alignas(std::hardware_destructive_interference_size) cache_isolated : public T {
  static constexpr std::size_t len = std::hardware_destructive_interference_size;
  std::array<char unsigned, (len - (sizeof(T) % len)) % len> cache_line_padding;
public:
  template<typename... Params>
  cache_isolated(Params&&... args) : T{ std::forward<Params>(args)... } {}
};
 
Of course if 'T' is a class marked 'final' then inheritance wouldn't work here, and it would need to be a sub-object instead.

And then individual compilers could provide more specific optimised implementations.
-- 
 Std-Proposals mailing list
 Std-Proposals@lists.isocpp.org
 https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals