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.

AppGameKit Classic Chat / Zero out arrays - necessary precaution or not?

Author
Message
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 30th Apr 2014 23:39
I read somewhere that when arrays are first made it's good practice to zero out all the values in the array just in case. Just wondering what your experience is...Is this a necessary precaution or a waste of time?
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 30th Apr 2014 23:45
I'd say - yes - unless the compiler does it for you. It's worth finding out when this happens. For example, in Object Pascal all values are cleared to null when an object is created, but static arrays are not cleared.

-- Jim - When is there going to be a release?
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 30th Apr 2014 23:55
Yes. I've had quite a few instances where UDT arrays will have some garbage in them. Same thing with memblocks. I've not had an issue with standard type (string, int, float) arrays, but I've learned the hard way with AppGameKit that it is better safe then sorry.
You can also undim a non-existent array and that will kill globals...

The only way to find the conditions where this happens is if you have many arrays and test them on Android. It doesn't seem to happen on windows. It may also happen on iOS. I've had too many mysteries solved by zeroing arrays.

Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 1st May 2014 00:51
I've never had a problem with this.

=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 1st May 2014 01:23 Edited at: 1st May 2014 02:29
Quote: "The only way to find the conditions where this happens is if you have many arrays and test them on Android. It doesn't seem to happen on windows."


This sounds exactly the bug I'm suffering from. I'll try zeroing all the arrays.

>Edit<
That fixed it!! Well, I've added code to zero all my arrays at creation (Both UDT and standard), but whilst I was adding this I found another instance where I had accessed an array using a value greater than the defined array size.

DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 1st May 2014 09:31
Ok, sounds like a safer route! Let me go through and find those DIM's!

Prof - yes, I've also read from an array using a subscript beyond the size of the array (I'd have thought that would throw up an error?) - that had me stumped for a while - no error but my sprite IDs just went crazy.
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 1st May 2014 09:33
Sorry - can't edit posts...

Undim'ing non existent arrays should surely throw up an error? That sounds like a nightmare to debug if it just silently does it whilst killing of a few globals!
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 1st May 2014 10:43
I was pretty annoying. Fortunately I structure my programs so that I can track things down quickly. I had to track the state of the global throughout the program to see where it was changing. It wound up leading to where I was undim'ing an array and noticed I had a typo in the array name. I reported this and I hope that Paul will fix it, but who knows.

This and the issue with being able to access arrays out of bounds makes me concerned as to what other potential issues AppGameKit has with memory management.

Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 1st May 2014 11:16
Hopefully this will all be fixed with the compiler update.

DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 8th May 2014 22:54
So...when you UnDim should you zero out beforehand to avoid junk being in memory or is that a step too far in the paranoia department?
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 8th May 2014 22:55
I've never thought about doing that, shouldn't be necessary as long as you remember to initialize arrays and globals with values in them before checking anything against them.

DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 8th May 2014 23:34
OK, thanks.

Login to post a reply

Server time is: 2024-04-28 11:48:04
Your offset time is: 2024-04-28 11:48:04