哪种结构设计具有更好的空间位置?
-
28-09-2019 - |
题
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
}
}
我认为第二种情况具有更好的空间位置,因为所有数据都交错,应同时加载到缓存中。在这两种情况下,我都将同时处理所有领域。有任何输入吗?
解决方案
我可以建议您在Cachegrind或其他一些缓存Profiler下尝试使用您的数据集吗?这可能比在空间区域等方面的理论更有效。取决于代码的访问模式,您可能会提出一些令人惊讶的结果。
其他提示
我们缺乏重要的细节,即目标架构。
两种方式都可以达到相同的空间位置。
不隶属于 StackOverflow