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
}
}
我认为第二种情况具有更好的空间局部性,因为所有数据都是交错的,并且应该同时加载到缓存中。在这两种情况下,我将同时处理所有球体。有输入吗?