In case 1 you do:
array1[0] -> [memory area of 10] array1[1] -> [memory area of 10] ... array1[N] -> [memory area of 10] ...
Note. You cannot assume that the memory area is continuous, there may be spaces.
In case 2 you do:
array1 -> [memory area of 100]
Case 3 is similar to case 2, but does not initialize the memory. The difference between cases 1 and 2 and 3 is that in the first case, you really have a 2D memory structure. For example, if you want to swap lines 1 and 2, you can simply swap pointers:
help = array1[1] array1[1] = array1[2] array1[2] = help
But if you want to do the same in case of 2 & 3, you need to make real memcpy. What to use? Depends on what you do.
The first method uses a memory bit: if you had a 1000x10 array, then the first version will use 1000 * 8 + 1000 * 10 * 8 (on a 64-bit system), while 2 and 3 will only use 1000 * 10 * 8.
susundberg
source share