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 / Variable limit

Author
Message
Doveyy04
8
Years of Service
User Offline
Joined: 30th Apr 2012
Location:
Posted: 26th Sep 2012 14:30
Is there a limit on how many variables and string$ you can have in ur program and if so is there any trick to get more like using the DIM command. Thanks for any help
baxslash
Valued Member
Bronze Codemaster
14
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 26th Sep 2012 15:07
The only limit really is the amount of memory on the device you are playing on. I wouldn't worry about hitting a memory limit from using too many variables, you're much more likely to meet a limit from using too much media.


this.mess = abs(sin(times#))
Doveyy04
8
Years of Service
User Offline
Joined: 30th Apr 2012
Location:
Posted: 26th Sep 2012 15:20
What do you mean by too much media? My program has quite a few png images and will have a few simple moving sprites (no collisions or anything) but mainly it's texted based with a hell of a lot of variables maybe 500 when am done and 100 of so string$. Is there any way of checking the memory status or is it just a case of checking the frame rate is near to 60
baxslash
Valued Member
Bronze Codemaster
14
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 26th Sep 2012 15:22
500 is next to nothing, do some tests using these commands: http://www.appgamekit.com/documentation/Reference/Benchmarking.htm

Or check the results of "screenFPS()"


this.mess = abs(sin(times#))
BatVink
Moderator
17
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 26th Sep 2012 17:09
Those numbers are not a problem. I have an array of 36,000 floats in one of my programs, plus hundreds of other variables.

Hodgey
11
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 27th Sep 2012 03:47
As you're new to programming it's best to learn the sizes of datatypes now. When I first started out, I made the mistake of ignoring this but I've since caught up.

Every variable you create gets stored in RAM (memory). The datatype of the variable determines how much RAM is used. For example, integers and floats use 32 bits which equals 4 bytes. Strings are arrays of characters which are typically one byte each. For example "Hello World" uses 11 bytes, space included (it may actually be 12 bytes if there is a NULL character included by AppGameKit internally but we won't worry about this).

Arrays are like a table of variables and the amount of RAM an array takes up is Number_of_Elements * Array_Datatype_Size. An array of 10 integers will take up 40 bytes of RAM.

Let's do the maths with your current program. You have 500 variables (I'm assuming ints and floats) and 100 strings lets assume the average string character count (spaces included) is 1000. So we have 500*4 + 100 * 1000 = 102,000 bytes. Divide this by 1024 to get the number of kilobytes which equals approx. 100kb. The amount of RAM your variables are taking up (assuming 1000 chars per string) is 100kb. BatVink's array of floats alone is 40% larger. Compare 100kb to the size of your .png files. As baxslash stated, you're far more likely to run out of memory by loading in too much media than using too many variables.

Login to post a reply

Server time is: 2021-03-05 10:55:54
Your offset time is: 2021-03-05 10:55:54