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.

Newcomers AppGameKit Corner / unused variables eat up lots of memory? Subscribe Post Reply

Gustavo Woltmann
Years of Service
User Offline
Joined: 11th Mar 2016
Posted: 11th Mar 2016 21:11
have a poor understanding of memory load and an impatience for games that routinely crash, and figure maybe I can get help for at least one of those problems.

I have a type Coordinates with integer variables .X, .Y, .UU, .UV, .VU, .VV, .H, .K, .T which I've been using to keep track of moving sprites' intended destinations and configurations (for items that don't use physics, like alert boxes). It's convenient because I can assign a single variable to a collection of sprites and particle emitters that 'belong together' as part of one object.

Unrelatedly, I've also been trying to design a way to track mouse movement over time, to create a mousetrail on the screen. I'm planning to eventually create a program that evaluates how well a user traces around a circle with their mouse. For that, I've been using an array of type Coordinates[3600] to store the mouse pointer location each frame, for a maximum of sixty seconds. But in this case I only really need .X, .Y information per frame, which means I'm creating 25,200 integer variables that I'll never use.

Obviously I'm aware that I *can* create separate types, and will for this particular case, but this got me wondering just how careful and judicious I ought to be.

Will having AppGameKit create hundreds of thousands of empty initialized unused integer variables cause a significant memory/workload concern, on typical low-end mobile devices? Or do variables take up so little space individually that this is a drop in the bucket? Or does AppGameKit kind of ignore those variables until used?

I don't even know how to test the potential for problems, or the threshold for concern, since presumably any memory error would only occur when there's already a ton of sprites on screen and other stuff happening. All by itself, creating the array and filling its X and Y coordinates doesn't seem to cause any problems or slowdown.
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 11th Mar 2016 22:30
An integer is 4 bytes. Thus, an X/Y coordinate needs 8 bytes.
3,600 coordinates is 28.8 Kilobytes. This is nothing at all, about the equivalent of one extra image in your game.
I'm not sure if there is any other overhead for an array. They are actually created 50% bigger to allow for expansion without having to reallocate memory. It's still a small amount of memory.

You can destroy and create arrays by changing their length:

myArray.length = 100
myArray.length = -1

I have created a pointer tracking program in the past. I did it by adding a new point every time it was 5 pixels or more from the previous point. Unless time of the trail is also important, there is no need to record the same pixel multiple times. So even if you are wanting 1-pixel accuracy, you could reduce the number of points recorded significantly. Doing it this way also makes it a lot easier to draw the trail on the screen, and also save the data that makes the trail. I was saving signatures as metadata that could be reproduced from the saved data file.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt

Login to post a reply

Server time is: 2019-11-17 20:08:43
Your offset time is: 2019-11-17 20:08:43