Bug when redimensioning multi-dimension arrays? - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: Bug when redimensioning multi-dimension arrays? (/showthread.php?tid=2813) |
RE: Bug when redimensioning multi-dimension arrays? - 12centuries - 06-20-2024 (06-20-2024, 03:32 PM)SMcNeill Wrote: Your arrays are from (0 to 5, 0 to 5), which affects them as above. You're ust printing them from (1 to 5, 1 to 5), and that makes it seem as if values are totally scrambled or even lost.AH CRAP, I missed the second part of your post. My original code (that led me here) has an OPTION BASE 1 and I forgot to do that in my test code. PEBCAK. Thank you sir, that explains a lot. So now I'm wondering if it would be possible to implement the array copying routine that you and bplus both outlined (copying to a new array) into the REDIM _PRESERVE routines in the QB64 source so that it would work as people might expect. I'm sure there are more considerations here that I'm recognizing, but has that been looked at? RE: Bug when redimensioning multi-dimension arrays? - SMcNeill - 06-20-2024 (06-20-2024, 03:41 PM)12centuries Wrote:(06-20-2024, 03:32 PM)SMcNeill Wrote: Your arrays are from (0 to 5, 0 to 5), which affects them as above. You're ust printing them from (1 to 5, 1 to 5), and that makes it seem as if values are totally scrambled or even lost.AH CRAP, I missed the second part of your post. The problem with adding it into the source is simple: How do you account for all possible variations of array that a user might have? DIM x(0 to 1, 1 to 4) REDIM x(1 to 3, 4 to 17) <--- Now what the heck does the source look like for this?? DIM x(-1 to 3, 2 to 14, 1 to 27, 11, apple_number, cheestos, and_frogs) <-- and what would the source look like to handle this when its redimmed? Just try and imagine the routine you'd have to write for that, and it'd have to allow resizing of the LBOUND and the UBOUND... on one, or more, or all indexes... while preserving data that may or may not be the original range anymore... We've looked at it... blinked stupidly to each other a few times... and then said, "Umm... Yeah. No. Folks can write what they need for their one specific case. It'd be just about impossible to support fully for all use cases." At least, I know it'd be impossible for *ME* to try and support it. I'd get completely lost in the complexity of trying to write something that expanded for any number of dimensions, and any index range, and then resized to any other index ranges... So we do what's really simple: Preserve the data in the old array and simply move it into the new array. That'll handle REDIM and PRESERVE as long as you resize only by the RIGHTMOST index. For anything more than that, we leave it for the user to have to write their own routine to handle it. As you can see, just something as simple as OPTION BASE 1 can really change how things look/work and perform. For us to change the source, we'd have to account for ALL those possible changes which the end user might need -- and honestly, that's just overwhelming to even think about in this case. That said, if someone else wants to sit down and sort out how to do it, we're an open-source project. We'll be more than happy to add in any additions which they come up with for the problem. I don't imagine that it's impossible to do; but honestly it's not something that I ever think the current devs will ever work on. It's low priority, complex as heck, and unless there's some library already made out there that one can just plug into to do this type of thing for us, I certainly wouldn't hold my breath waiting for us to do it ourselves. RE: Bug when redimensioning multi-dimension arrays? - bplus - 06-20-2024 it might be handy to be able to use the same array name throughout an app so redim would be needed to do that and it might be useful to convert a 2d array to bigger row size (more x's per row) and really not hard to convert the for sure code i showed into a sub for resizing x's. as stated already by steve just adding more rows wont be a problem for redim forget _preserve though. so not so complex if restrict yourself to 2d array and i'd say drop option base to make subs and functions more portable to other apps. complexity relieved further if we can assume not switching the lbounds of the array. complexity reduced again if we are only expanding the array... so how long would it take to rewrite my example to a sub? now i am curious to see if it's as simple as i think ;-)) RE: Bug when redimensioning multi-dimension arrays? - bplus - 06-20-2024 oK redim wont let me change the array ??? Code: (Select All) Dim Grid(1 To 5, 1 To 5) As Long RE: Bug when redimensioning multi-dimension arrays? - SMcNeill - 06-20-2024 (06-20-2024, 04:58 PM)bplus Wrote: oK redim wont let me change the array ??? Why would it? That's not a REDIMable array. RE: Bug when redimensioning multi-dimension arrays? - bplus - 06-20-2024 ok that blunder fixed, fixes code, added a second test of sub Code: (Select All) ReDim Grid(1 To 5, 1 To 5) As Long RE: Bug when redimensioning multi-dimension arrays? - SMcNeill - 06-20-2024 And I's brokes it already! Code: (Select All)
Which goes to show how complex an universal routine would be to write and toss into the core language. This is breaking now, when one array is smaller than the other. You need to check for lbound on both, ubound on both, for all dimensions.... only copy the parts that overlap... and then expand that to work for any number of dimensions which someone might have in their array. RE: Bug when redimensioning multi-dimension arrays? - bplus - 06-20-2024 Quote:And I's brokes it already! reread my reply 13, expansion only RE: Bug when redimensioning multi-dimension arrays? - SMcNeill - 06-20-2024 (06-20-2024, 05:10 PM)bplus Wrote:Quote:And I's brokes it already! Code: (Select All)
There. I fixed it for downsizing one, while expanding on the other index. RE: Bug when redimensioning multi-dimension arrays? - Dimster - 06-20-2024 CoPilot says it can REDim a 3 Dim array into a $ dim array and preserve the values from the original array. Here is it's suggestion. Certainly! To redimension a 3D array to a 4D array while preserving all values in QB64pe, you can follow these steps:
I'll have to see if Gemini can do it. |