• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Variables vs Calculations

Status
Not open for further replies.
Level 6
Joined
Jun 14, 2008
Messages
191
I'm curious to know if its better to do a calculation once and save it in a variable, or calculate it out, saving you the memory.

Say you have to either calculate 20 values every 1 second using 8 variables, 200 times (one for each unit).
(so in essence 20*200=4000 possible calculations, using 8*200=1600 memory slots)

or

Calculate 5 values every 1 second using 12 variables, 200 times (one for each unit).
(so in essence 5*200=1000 possible calculations, using 12*200=2400 memory slots)

Which would be better and why?
 
Level 6
Joined
Aug 13, 2008
Messages
197
i am not too sure about it but i believe it boils down to the computer cpu processing power vs it ram
Here what i reasoned:
since the typical computer (3.0 cpu / 1.5 ram) have much more more processing power than ram. It would be best to have more calculation than memory usage.
 
Level 6
Joined
Jun 14, 2008
Messages
191
Thanks Epimeliad. That is exactly what I wanted to know.

That's how I started to do it but I realized I could have made it easy on myself and possibly saved the players delay/lag if more variables were better. So good to know for sure. Ty.
 
Level 2
Joined
Dec 4, 2008
Messages
24
This is a smart question, but in practice, you don't have to think about this a lot.
Basically, each calculation takes both processing time and a very small bit of ram, where stored memory takes only ram (and HD if you've spent all your ram and are using paging file). So, if you are doing too many calculations, and the game laggs because of that, go for storing it in RAM. If you are, however, using too much ram, you should use processing time over ram, cause this way it'll spend more of it, and use only a very small temporary amount of ram, meaning it'll get deleted as soon as the calculation is done.
 
Status
Not open for further replies.
Top