有没有办法强制存储在C中的高速缓存中的变量? [英] Is there a way to force a variable to be stored in the cache in C?
问题描述
我刚做了一次电话采访,其中有人问我这个问题。我知道的方式寄存器或堆或堆栈来存储,而且专门缓存?
I just had a phone interview where I was asked this question. I am aware of ways to store in register or heap or stack, but cache specifically?
推荐答案
不是在C作为一种语言。在GCC作为编译器 - 寻找<一href=\"http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html\"><$c$c>__builtin_$p$pfetch$c$c>.
Not in C as a language. In GCC as a compiler - look for __builtin_prefetch
.
您可能会感兴趣的阅读 什么每个程序员应该知道内存 。
You might be interested in reading What every programmer should know about memory.
只是为了澄清一些混乱 - 缓存在物理上是在硬件分立的存储器,而不是在机器的软件抽象。在缓存中的词总是与主内存地址相关联。这是从CPU寄存器,这被命名为/从RAM分别处理不同的
Just to clear some confusion - caches are physically separate memories in hardware, but not in software abstraction of the machine. A word in a cache is always associated with address in main memory. This is different from the CPU registers, which are named/addressed separately from the RAM.
这篇关于有没有办法强制存储在C中的高速缓存中的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!