06-20-2024, 03:25 PM
(This post was last modified: 06-20-2024, 03:32 PM by 12centuries.
Edit Reason: missing information from graphic
)
(06-20-2024, 02:07 AM)SMcNeill Wrote: [...] So, when using REDIM _PRESERVE, one can resize on the LAST index only, and have the data stay in place and organized. Otherwise, the indexes get scrambled (the data still stays in one block, but the indexes to that block no longer match the same format).Okay, this makes a bit more sense, thanks for taking the time to explain it!
But I believe there is a bit more going on here that you're outlining (maybe you're dumbing it down for me).
So take a look at the array I was getting after I redimmed it:
As you can see, the first "column" values are completely absent from the final array, and many of the "middle" values for each column are missing, as if they're lost in a hidden row just outside the array grid.
So if I'm looking at this as a single block of memory, it initially looks like this:
Code: (Select All)
Column 2 Column 3 Column 4 Column 5 Column 6
┌──────┴─────┐ ┌──────┴─────┐ ┌──────┴─────┐ ┌──────┴─────┐ ┌──────┴─────┐
01 06 11 16 21 02 07 12 17 22 03 08 13 18 23 04 09 14 19 24 05 10 15 20 25
After redimming it, it looks like this:
Code: (Select All)
?? Column 2 ?? Column 3 ?? Column 4 ?? Column 3 new data
┌┐ ┌──────┴─────┐ ┌┐ ┌────┴────┐ ┌┐ ┌──────┴─────┐ ┌┐ ┌────┴────┐ ┌──────┴─────┐
00 02 07 12 17 22 00 03 08 13 23 00 04 09 14 19 24 00 05 10 20 25 00 00 00 00 00 […]
Some of the values have (apparently) completely disappeared (1, 6, 11, 16, 15, 18 and 21), but they are (evidently) still in memory, because if I redim back to the original size:
Code: (Select All)
REDIM _PRESERVE Grid(5, 5) ' back to the original size
Then I get the original array back, including those "missing" numbers:
Code: (Select All)
1 1 2 3 4 5
2 6 7 8 9 10
3 11 12 13 14 15
4 16 17 18 19 20
5 21 22 23 24 25
I'm wondering where those "missing" numbers went and why they're not accessible to the array after redimming to a larger array, and why they return after redimming to the original size. Also, why there are extra zeros in between the existing data after the initial resize.
I think I may take a look at the source code for this...