❔ Separating struct array data
Is it worth separating fields of array data (struct array) into different data structures so that cache hit count increases? Because the struct size reduces and more elements of the array can be cached
When I say separation I mean smart separation (relevant data in a struct)
4 Replies
I don't think there's enough information to say much I'm afraid. It probably all comes down to usage patterns: if you're accessing the fields together, having them together in cache is a good thing; if you're accessing elements in turn and not jumping around a lot, it probably doesn't matter that the array is being loaded into cache a chunk at a time.
Get a profiler out and see for yourself, with your usage patterns
Yes, thanks
and another question, if I have a 3d array, it can detect the access pattern to cache elements?
I mean, it does not matter if I loop over i,j,k or k,j,i ?
It probably will. A multidimensional array is just a flat array, and it does the maths to work out which element corresponds to a particular i,j,k
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.