edgarmtze
edgarmtze

Reputation: 25058

jagged bidimensional arrays and contiguous memory in c#

I have seen that declaring a bidimensional array as a jagged array is fine

int[][] jagged = new int[3][];

but when doing some optimization at memory level in code, it is more convenient to use [,] as a definition of a matrix and use blocks of memory...

so can you explain if this is true? I guess the [,] takes a block of memory and the access of elements is faster rather than lookimg in several parts of memory in a jagged bidimensional array....

Upvotes: 0

Views: 397

Answers (1)

logicnp
logicnp

Reputation: 5836

Yes, when an array is allocated as [,] , it is always given contiguous memory, so depending on what you want to do, it may be faster, convenient, etc

Upvotes: 1

Related Questions