• All, Gmail is currently rejecting messages from my host. I have a ticket in process, but it may take some time to resolve. Until further notice, do NOT use Gmail for your accounts. You will be unable to receive confirmations and two factor messages to login.

Help reduce memory usage

msmalik681

OpenBOR Developer
Staff member
I am trying to optimise my scripts to use less memory as my resources are 20mb but my game takes 70mb to run.  Here is what I have tried:
  • Changing global variables to local variables.
  • Use forwarding scripts for scripts other then animation scripts
The above had little to no difference on my memory usage.  I may not sound like I tried much but doing these changes to all my scripts took quite a while.


Is there any way to reduce memory usage without removing scripts.  Is anything planned for engine updates to fix this problem ?
 
A variable is a variable and takes up the same amount of space while it exists - doesn't matter if it is global, local, or anything else. The reason we advise trying to use locals is they clean themselves, and have a limited scope. It's just universally poor practice to use global vars when you don't have to - no matter what engine or language you are using.

IOW, switching variable scopes won't do anything what so ever to curtail memory consumption other than help ensure you don't have active variables left over that aren't actually doing anything. There are many things you can do to reduce memory use though. Use #import whenever possible, and only #import what you need. Animation scripts are not inherently bad, nor are updates. It's just both tend to be overused for things other events are much better equipped to handle.

Another common practice that eats up loads of memory is building a single universal script (usually animation, but this applies to any event script) and applying it to every single model. Don't do this. A model should only get what it needs and nothing else. If there is a base set of functions every model uses, then build said universal script file with only those universal essentials - nothing else, and make sure they are #imported, not #included. Then the individual models should each have their own animation scrip that #includes the universal list of #imports, and then #imports whatever extra functions that particular model needs.

There's a lot more, but it would fill up this page and I have to get back to work.

DC
 
thanks for the insight any thing else you can post up at a later time would be much appreciated.
 
So I have been doing some digging and I discovered a problem. I tested openbor on a very light mod using a very old build the mod was running in game at 7mb (read from windows task manager) and this usage was consistent with older releases.  When I tried the new build 4556 the usage was 30mb that is a huge 23mb difference.  I started to back track and found the build 4107 changed something that caused the increased usage.


http://www.chronocrash.com/forum/index.php?topic=2128.0


I can only beg the developers to look into this as anyone aiming their mod for low ram systems like psp and wii may have to make unnecessary sacrifices.


Even though the above is true I tested my mod on a psp and it only took up 12mb ram compared to windows that takes 70mb ram not sure why maybe the wiii will be ok but I have not tested yet.
 
I am having issues with out of memory.
I am learning how to add animation backgrounds to the title and character selection screens.
When I start game, there is no issue,
but if I loop the title screen then char selection screen back and forth for like 20 times, then it runs out of memory.
I clear the global variables and killentity between title and char selection screens.
Therefore, I just can't understand how I get out of memory issues after looping it for 15-20 times.
Can someone please help me understand more about the memory usage?
How do I show the memory usage in the log file?

Thank you
 
I am having issues with out of memory.
I am learning how to add animation backgrounds to the title and character selection screens.
When I start game, there is no issue,
but if I loop the title screen then char selection screen back and forth for like 20 times, then it runs out of memory.
I clear the global variables and killentity between title and char selection screens.
Therefore, I just can't understand how I get out of memory issues after looping it for 15-20 times.
Can someone please help me understand more about the memory usage?
How do I show the memory usage in the log file?

Thank you
Probably there's some update scripts loading things to memory in a moment where this should be stopped. I suggest to check all the variables in your animated select screen script to see if they are working properly.
If I'm not wrong there's a variable named "counter" in this script that acts as a flag to turn on/off the animated select screen.
 
Probably there's some update scripts loading things to memory in a moment where this should be stopped. I suggest to check all the variables in your animated select screen script to see if they are working properly.
If I'm not wrong there's a variable named "counter" in this script that acts as a flag to turn on/off the animated select screen.
Yes, there is counter to make sure the animation only triggers once and continues looping.
I have found that
I have functions
ClearGlobalvarArrays();
InitializeGlobalArrays();
If I remove these two functions off the in character selection screen, then it can run 40-50 times more. Somehow these 2 functions keep on adding more stuff to the memory instead of cleaning up
This doesn't make senses to me as I thought the global variables and sprites need to be removed at some points to free memory.
I'll open up a topic and post the code in there. Out of memory seems to be a big problem for me as my game will be in 1080p.
 
I have a question too, when you have set a update script that load things like variables and images it makes your memory going up over time?
 
I have a question too, when you have set a update script that load things like variables and images it makes your memory going up over time?

It depends. The engine uses smart loading for most resources. For, example if you try to load a sound file "punchedintheface.wav" and there's already a "punchedintheface.wav" loaded, the engine doesn't load another copy or reload over the original. The load function just returns the ID for the file already in memory.**

Still, you generally don't want to load things in an update main() because it's running that load attempt around 250 times a second. Why do that?

Even if you put a limiter variable or something to stop loading over and over, it's still likely you have a flaw in design if you're loading in an update script. That sort of work should be done elsewhere before the update needs the resource.

**An important caveat of OpenBOR's smart loading is that if for some reason you DO want to replace an existing resource in memory, you have to explicitly tell OpenBOR to unload it first.

DC
 
Back
Top Bottom