Which of these two dimensional array are advantageous to use and why?

后端 未结 5 1925
故里飘歌
故里飘歌 2021-01-26 18:54

In a facebook group, I saw a question like :

If a row dominated two dimensional array in the following which one is advantage and why?

         


        
5条回答
  •  北恋
    北恋 (楼主)
    2021-01-26 19:37

    There is no difference in theory.

    The practical advantage is in cache locality. If you access locations which are far apart, you increase the number of cache misses, which in turn makes the code run slower.

    Depending on your processor cache size, you would perhaps need to replace 1000 with some reasonably bigger number in order to perceive the effect.

提交回复
热议问题