Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Bug Reports / Redimming multidemensional arrays broken U6.5

Author
Message
Lost in Thought
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 13th Mar 2007 12:21 Edited at: 13th Mar 2007 12:55
This code should write all 1's to the file, yet it writes 1's for a while and then 0's. If you move the dim to outside the loop (only dim it once) it works properly.



The size of the array also effects where it fails. Change the 300 size to 1040 and the failure point moves from around 60 to 108.

This has all of my projects pretty much dead in the water.

[edit] I tracked this back all the way to U6.0 here 0_o Wonder why it hasn't been a problem before. Guess it's just a certain combination. I thought this had been posted and fixed a pretty good while ago, but can't find any of the old threads.

[edit2] Found out why I haven't ran into this before ... it only breaks when you have more than 2 demensions.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th Mar 2007 20:45
Quote: "If you move the dim to outside the loop (only dim it once) it works properly."


Which is the right thing to do, of course.

I'm amazed the other version ever worked. Is it supposed to?

[I vaguely recall seeing some discussion of this sort of thing but thought at the time that it seemed a very dodgy thing to do, even if the compiler allowed it. If the dim command is reserving a bit of memory for your array (and initialising it to zero) it seems very unlikely that you should expect anything other than zero except for the final element. Or is that the bug?

I modified your code to write an incremented counter (from 1 to 4800) to make it easier to see what was being written from where. The final entry in the file was indeed 4800 - but I expected the others to be zero - they weren't.
LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 13th Mar 2007 22:40
DIM initialises the data, and can recreate the array in some cases (size changes). You can also use DIM in the above way to 'redim' the array larger or smaller, but you should restrict this to a single dimension array for data integrity. If there is a large user opinion that the data should only be initialised upon creation, and subsequent dims used for resizing, then post here for a dicussion on the matter.

"Small, smart, and running around the legs of dinosaurs to find enough food to survive, bedroom programmers aren't extinct after all "
Lost in Thought
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 13th Mar 2007 22:40 Edited at: 13th Mar 2007 22:45
Lee made it so when you redimmed arrays it saved the old elements. This is the only way we can resize multidemensional arrays. I can't just move it outside the loop as I don't know how many elements I have until I read the whole file. That loop was just to show the bug and to show that even when the array sizes don't change it still breaks it. 0_o

Have a look at using that same code with single or 2 demensional arrays. They work perfectly.

[edit]
Quote: "but you should restrict this to a single dimension array for data integrity."


We have the array insert and delete commands for single demensional arrays. This is all we have for multidemensional arrays. It needs to be fixed. It works perfectly with 2 demensional arrays. Or make the array insert and delete element commands work on multidemensional arrays. I can't just do dim test(10000000000,1000000000,10000000000) until I read the whole file 0_o

Or could we possibly have a copy array command. Then we could redim a new temp array and copy the data over and remove to old array, though this is really wasteful and will likely be slow.

IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th Mar 2007 00:02
@Lee,
This is functionality you added around 5.8, so that if you DIM an existing array, you change it's size and preserve it's contents as far as possible, no matter the number of dimensions.

Looking at LiT's original code, I would expect that code to work, although not efficiently due to the amount of memory allocs and copying taking place.

Lost in Thought
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 14th Mar 2007 00:31
Yeah that was a bad example, I just posted it quickly as it reproduced the bug. The actual code is closer to this:



Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 14th Mar 2007 00:36
I'm very strongly with LiT and IanM on this. I really found the functionality added in v5.8 very helpful for my project. If its been changed, I'm very glad I'm on v6.4 and not v6.5!

Cheer if you like bears! Cheer if you like jam sandwiches!
"I highly recommend Philip" (Philip)
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Mar 2007 01:44
I'm easy on the matter - as long as it is clearly documented in the Help files.

But I certainly agree that if repeated dim's are allowed without undimming first, then 1- and multi-dimensional arrays should be treated in the same way. I can see why Lee might hope that everyone would want arrays to be initialized to zero ...
Cash Curtis II
19
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 14th Mar 2007 04:54
Let's just not slow down single dimensional redimming. I use that for everything.


Come see the WIP!

Login to post a reply

Server time is: 2024-05-27 01:09:47
Your offset time is: 2024-05-27 01:09:47