【发布时间】:2010-11-27 19:37:48
【问题描述】:
struct{
Vector3* centers;
float* radii;
float* colors;
unsigned int size;
}Spheres;
对
struct Sphere{
Vector3 center;
float radius;
float color;
};
struct{
struct Sphere* spheres;
unsigned int size;
}Spheres;
使用示例
void spheres_process(){
int i;
for(i = 0; i < Spheres.size; ++i){
// do something with this sphere
}
}
我认为第二种情况具有更好的空间局部性,因为所有数据都是交错的,应该同时加载到缓存中。在这两种情况下,我将同时处理所有球体。有什么意见吗?
【问题讨论】:
标签: c caching data-oriented-design