Performance of 2-dimensional array vs 1-dimensional array

后端 未结 6 1320
谎友^
谎友^ 2020-11-27 14:46

In C, is there a difference in time and space between an m×n 2-dimensional array vs a 1-dimensional array of length m×n (for large values of m and n)? Will accessing element

6条回答
  •  孤街浪徒
    2020-11-27 15:12

    I don't think there's any difference. Internally, c treats a two dimensional array like several one-dimensional arrays in sequence.

    However, as with all things performance, your mileage may vary. There may be some kind of subtle pointer arithmetic difference. Run timed tests on both scenarios. Whichever one runs faster wins.

提交回复
热议问题