Structure of arrays and array of structures - performance difference

后端 未结 4 1642
情深已故
情深已故 2020-12-06 01:24

I have a class like this:

//Array of Structures
class Unit
{
  public:
    float v;
    float u;
    //And similarly many other variables of float type, upto         


        
4条回答
  •  无人及你
    2020-12-06 02:22

    Structure of arrays is not cache friendly in this case.

    You use both u and v together, but in case of 2 different arrays for them they will not be loaded simultaneously into one cache line and cache misses will cost huge performance penalty.

    _mm_prefetch can be used to make AoS representation even faster.

提交回复
热议问题