0
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
    }
}

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

4

2 回答 2

0

我可以建议在 cachegrind 或其他缓存分析器下尝试使用您的数据集吗?这可能比空间局部性等理论更有效。根据代码的访问模式,您可能会得出一些令人惊讶的结果。

于 2010-11-27T23:56:29.927 回答
0

我们缺乏重要的细节、目标架构。

两种方式都可以实现相同的空间局部性。

于 2010-11-27T20:06:54.040 回答