什么是“缓存友好”代码?“缓存不友好代码“和”缓存友好“密码?如何确保编写高效缓存代码?
3 回答
湖上湖
TA贡献2003条经验 获得超2个赞
// Cache-friendly version - processes pixels which are adjacent in memoryfor(unsigned int y=0; y<height; ++y){ for(unsigned int x=0; x<width; ++x) { ... image[y][x] ... }}
// Cache-unfriendly version - jumps around in memory for no good reasonfor(unsigned int x=0; x<width; ++x){ for(unsigned int y=0; y<height; ++y) { ... image[y][x] ... }}
- 3 回答
- 0 关注
- 754 浏览
添加回答
举报
0/150
提交
取消