2021-05-08, 08:08 PM
2021-05-08: Resize 2D Arrays
You can resize the slots in a 2D array, as long as the sum remains the same.? For example this array:
Has a grand total of 25 cells in which to store data.? Those can be reallocated to one slot of 21, and 4 slots of 1.? This is called a jagged array:
The compiler doesn?t know about these resizes, so you need to replace sizeof(arr[]) with jaggedsizeof(arr[0]); specifying an index because they?re all different.
You can also declare the array jagged initially:
You can resize the slots in a 2D array, as long as the sum remains the same.? For example this array:
Quote:
new arr[5][5];
Has a grand total of 25 cells in which to store data.? Those can be reallocated to one slot of 21, and 4 slots of 1.? This is called a jagged array:
Quote:
new arr[5][5];
// Make "arr[0]" 21 cells big, and all the others just "1".
Jagged_Resize(array, {0, 21}, {1, 1}, {2, 1}, {3, 1}, {4, 1});
The compiler doesn?t know about these resizes, so you need to replace sizeof(arr[]) with jaggedsizeof(arr[0]); specifying an index because they?re all different.
You can also declare the array jagged initially:
Quote:
new Jagged:arr[5]<21, 1, 1, 1, 1>;
printf("Slot 0 size: %d", jaggedsizeof (arr[0]));
printf("Slot 1 size: %d", jaggedsizeof (arr[1]));
printf("Slot 2 size: %d", jaggedsizeof (arr[2]));
printf("Slot 3 size: %d", jaggedsizeof (arr[3]));
printf("Slot 4 size: %d", jaggedsizeof (arr[4]));