2012-06-25 70 views
1

我知道數據類型或結構對齊,打包,填充問題等概念。我已經實現了一個單鏈表,其中每個節點佔用大約250個字節,即大約是緩存行大小的4倍64個字節。我的機器是英特爾64位架構。緩存對齊鏈接列表

現在單個鏈表實際上就是一個追蹤數據結構的指針,因此會遭遇大量的高速緩存未命中。爲了減少緩存未命中,我使用* posix_memalign *函數將每個數據結構節點對齊,以緩存64字節的邊界。現在所有鏈接列表節點都是緩存對齊的。

這樣做後,我發現鏈表的內存消耗大大增加,而且性能實際上已經惡化。任何人都可以解釋什麼可能會出錯?

回答

0

我不知道你用的什麼的malloc但這是從tcmalloc

// For use by exported routines below that want specific alignments 
// 
// Note: this code can be slow for alignments > 16, and can 
// significantly fragment memory. The expectation is that 
// memalign/posix_memalign/valloc/pvalloc will not be invoked very 
// often. This requirement simplifies our implementation and allows 
// us to tune for expected allocation patterns.