Is there a limit on global variables?

Started by Ethan D, Sun 12/04/2009 17:40:54

Previous topic - Next topic

Ethan D

I just want to know if having a lot of global variables could become a problem and if so how many would be a problem?

RickJ

Variables declared in the script are only limited by system resources.   Variables declared in the global script are made global using the export and import keywords

There is an editor pane that allows one to do the same thing that can be done in the script.   I declare my global variables in the global script so I don't know if this feature has an artificial limit or not.   

Trent R

No. A variable takes up so little space, and today's computers have so much space...

Someone will probably come by and tell you how many bytes each one is.

[Edit]: While Rick was posting... :P

~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

Ethan D


monkey0506

#4
Quote from: Trent R on Sun 12/04/2009 18:12:22Someone will probably come by and tell you how many bytes each one is.

char: 1 byte
short: 2 bytes
int: 4 bytes
String: 4 bytes + 1 byte per character in string
float: 4 bytes
bool: 4 bytes*
Any pointer: 4 bytes
Any enumerated type: 4 bytes*

So basically, if you have 512 MB of RAM then your computer wouldn't be able to handle more than 536870912 combined int, String, and float variables**. Of course to define that in the script, even if you were defining 1000 variables per line would still result in 536870 lines of script...so I think you would have fair warning that you were doing something foolish. Even as an array with 1000000 elements you would still have to define 536 of them.

So essentially your answer then becomes no. I can't say for sure if the Global Variables pane in the editor has a built-in limit, but even if it does you can always define them in the script.

*This is not actually documented anywhere. I'm basing this off my experience which shows that enums are stored as integer values.
**This is of course ignoring the fact that your system will require the use of at least some of your RAM.

Trent R

To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

Trent R

Sorry to raise an old post, but CJ PMed this to Miori who then posted it in another topic.

Quote from: CJ in PM on Fri 24/04/2009 13:44:53
GlobalInts and GlobalStrings are obsolete, and you should not be using them in new scripts. Use the Global Variables pane instead to create global variables -- this does not have a limit to how many you can create.


~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

Ethan D


SMF spam blocked by CleanTalk