Have a couple technical questions about Memory, Long Text Variables and Value Overflow :)

Hello there!

Iv been trying to look this stuff up but cant really find any answers, so i decided to ask here since i know theres plenty of you guys that know the ins and outs of this stuff :slight_smile:

So heres my questions…

  • Do long string variables affect memory usage? If so do you know more or less how much?

Iv been doing some cleaning on my culling script, and i noticed that after saving and loading there was a left over string variable with an ungodly amount of data… and im not exagerating by that, it holds all the data of every object culled, i can fix it by simply reseting the value after its used, but i was wondering just how much memory does a long variable really take… and if i should of been more worried about it.

  • Value overflow… well sorta, does having the possability of an ever increasing value gonna break something eventually?

The reason for this one is that im working on the Build Mode of my new game, and just made it so that the player can Rotate the build tiles.

I did this simply by changing the Angle of the tile in use to a new angle of Tile.Angle()+90 or -90.

This works perfect, but i was wondering, what if someone just keeps on rotating the same way and keep adding up, is that gonna cause issues?

…one last question purily out of curiosity…

  • I tend to lock my key presses behind a boolean, and most of the time i used a global boolean so that if a key is pressed while changing scenes, no funky stuff happens… the question is: Is there any reason to limit my global variables? or are they just the same as every other kind? As is, does a scene or object variable take up the same memory as a global? that kind of stuff.

Thank you so much for taking the time :slight_smile: <3

1 Like

I also thought of that and tried saving a variable with 10000000+ words but my game didn’t crash but the memory used did my fps was 56 even without any object but when I deleted the strings it was going to about 69 fps
And also u can’t save large numbers of text in an object variable if saved and loaded

Thanks man :slight_smile:

When i feel a bit better ill have a go at doing some testing and then post it on here!

I conducted some experiments and found the following results:

  • Maximum string length: I discovered that the maximum string length is approximately 134,000,000 characters. When I tried to exceed this limit, the program crashed. It is important to note that this limit may be lower on low-end devices.
    When reaching the limit but not exceeding it, the program would still run smoothly.
  • Rotation: I tested the rotation and found no effects. Even with very high rotation values (+110,777,777,767), the program did not crash. However, it is possible that the program may lag on low-end devices.
  • Global variables: I did not experiment with the third point, too many global variables.

Here is a screenshot:

1 Like

Thats pretty awesome work, thank you so much!

So from a quick google search, a string variable with 19 characters in Java Script takes about 109 bytes.

So if i scale it up… i know this probably isnt right, im just looking for a ball park.

If 19 characters = 109 bytes then 134,000,000 characters = 768736842 bytes

Which if im not mistaken is a wooping 768 Mb

I have no idea if stuff translates that way, but i should start watching my memory usage more often when using these silly long variables.

1 Like

Check this out…

So because i dont know when to stay in bed and curiosity was killing me to know how that translates to my game, i did a quick memory test.

So the game running not using my Culling Script which is what makes the strings with an ungodly amount of data…

The Memory runs at about 375 Mb

With the Culling Script simply being active…

The Memory run at about 390 Mb

This is because the culling script is culling all object off screen and storing all of its information in a Java Object. Thats a lot of data considering my game world is set to 100x100 tiles, and its storing their full names, position, object variables, timers, properties… and so on.

So that seems right, but check this wizardry out…

Now when i hit my save key, the script copies all of the data in the java object and puts it into a scene variable, that scene variable is then writen into a JSON.

So… basically i just doubled the silly amounts of data… the memory tho? No change.

Memory spikes up to 400 Mb during the save process, which is about a couple frames and then comes back down to 390 Mb, even tho now theres a new variable with a silly amount of data.

Now when i Load the game, the JSON puts all the data its holding into a new scene variable, and then that data is turned back into their original variables and the data on the java object is also loaded from the variable.

Then point is… now theres 3 times the silly levels of data.

The Memory usage? around 420 Mb.

Thats the highest it will go since that the whole process, even if i repeat the process ill just be reusing variables.

That goes to show just how well optimized GDevelop is when it comes to Memory usage, think the devs need way more credit for this sort of wizardry :slight_smile:

Ill still be adding something to clear the variables after use since its silly to just leave them like that, but it was a pretty awesome learning experience to know just how much a variable and its size can impact your game.

1 Like