加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 我怎么知道我的数组在缓存中?

发布时间:2020-12-16 10:43:34 所属栏目:百科 来源:网络整理
导读:可以说我的数组是32KB,L1是64 KB. Windows在程序运行时是否使用了部分内容?也许我无法使用L1,因为Windows正在使其他程序工作?我应该将程序的优先级设置为使用所有缓存吗? for(int i=0;i8192;i++){ array_3[i]+=clock()*(rand()%256);//clock() and rand i
可以说我的数组是32KB,L1是64 KB. Windows在程序运行时是否使用了部分内容?也许我无法使用L1,因为Windows正在使其他程序工作?我应该将程序的优先级设置为使用所有缓存吗?

for(int i=0;i<8192;i++)
{
  array_3[i]+=clock()*(rand()%256);//clock() and rand in cache too?
  //how many times do I need to use a variable to make it stay in cache?
  //or cache is only for reading? look below plz
  temp_a+=array_x[i]*my_function();
}

该计划是在C/C++.

对于L2也一样.

还有功能保存在缓存中吗?缓存是只读的吗? (如果我更改了我的数组,那么它会丢失缓存绑定?)

编译器是否创建asm代码以使用缓存更高的产量?

谢谢

解决方法

How can i know my array is in cache?

一般来说,你不能.一般来说,缓存由硬件直接管理,而不是由Windows管理.您也无法控制数据是否驻留在缓存中(尽管可以指定不应缓存内存区域).

Does windows use some of it while program is running? Maybe i am not able to use L1 because windows is making other programs work? Should i set priority of my program to use all cache?

L1和L2高速缓存由在给定核心上运行的所有进程共享.当您的进程正在运行时,它将使用所有缓存(如果需要).当有上下文切换时,部分或全部高速缓存将被逐出,具体取决于第二个进程需要什么.因此,下次上下文切换回您的进程时,可能必须重新填充缓存.

但同样,这一切都是由硬件自动完成的.

also functions are kept in cache?

在大多数现代处理器上,有一个单独的缓存用于指令.参见例如this diagram显示了Intel Nehalem架构的安排;注意共享的L2和L3高速缓存,但是单独的L1高速缓存用于指令和数据.

cache is read only?(if i change my array then it loses the cache bond?)

否.缓存可以处理修改后的数据,尽管这要复杂得多(因为the problem of synchronising multiple caches in a multi-core system).

does the compiler create the asm codes to use cache more yield?

由于缓存活动通常全部由硬件自动处理,因此不需要特殊指令.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读