2010-11-27 62 views
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 
    } 
} 

我認爲第二種情況下具有更好的空間局部性,因爲所有的數據是交錯的,應在同一時間被加載到緩存中。在這兩種情況下,我將同時處理所有領域。任何輸入?

回答

0

我可以建議在cachegrind或其他緩存分析器下嘗試使用您的數據集嗎?這可能比在空間局部性上進行理論化更有效。根據代碼的訪問模式,您可能會得到一些令人驚訝的結果。

0

我們缺乏重要細節,目標架構開始。

兩種方式都可以達到相同的空間位置。

+0

目標架構是x86,我正在使用GCC 4.5.0。你還喜歡其他什麼細節? – ytrp 2010-11-27 20:11:55