Is there a way in C++ to specifically put a certain variable in the processor's cache?
If not is there a way with inline x86 assembly code?
Printable View
Is there a way in C++ to specifically put a certain variable in the processor's cache?
If not is there a way with inline x86 assembly code?
No, and no.
There is very little control over the cache from a software point of view (besides being able to say "this memory can be cached/this memory cannot be cached").
In almost every case, the processor makes the most intelligent decisions as to how it caches.
if you simply access the variable it will most likely be cached. you cannot control how long it stays there though, it could be removed (ie. flushed to memory and overwritten) at any time.