top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What all are the differences between Rectangular and Jagged Array in C#

0 votes
470 views
What all are the differences between Rectangular and Jagged Array in C#
posted May 9, 2017 by Jdk

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Jagged array is basically an array of arrays. This means that there are several arrays living in memory. Each as it's own lifetime.

Because Unity script (through .Net) is a managed runtime, object destruction happens out of user control. So part of a jagged array can be release while another part stay alive longer. For this reason it is bad on performance (and also it introduces a level of indirection when accessing values).

On the other hand if you have to store arrays of different size then there is no other solution. Using a rectangular array will use to much memory (you will have to allocate arrays with the biggest length of all your desired arrays, resulting in waste of place).

Jagged arrays are not really bad on performance if they are kept small (that is to say if don't have a lot of arrays in the first dimension).

answer Jul 11, 2019 by Rushabh Verma R.
...