Page 1 of 1
Efficient use of variables?
Posted: Fri May 05, 2006 11:21 am
by tekproxy
I notice a lot in the 096 distro code that variables are set to 0 when not used anymore. For example:
Code: Select all
function HitScript(params)
attacker := params[1];
defender := params[2];
cake := params[3];
params := 0;
Is this a good practice? Does it really help?
Oh, and what ever happened to all those escript optomization guides you had on your site Muad? Your site is down.

Posted: Fri May 05, 2006 12:14 pm
by Yukiko
Well, not knowing how POL works internally, and just looking at it from my limited point of view, I would think that if, in your example, params was equal to POL objects, which we learned are references, setting params equal to 0 might have little or no effect. If however you have a variable like this:
Code: Select all
var fred := "A very long string of letters entered here to take up lots of space in memory for my example.";
and you set fred to zero after use, that probably would release a good size chunk of memory. However, setting a string variable to an integer value is not proper ettiquette even if POL/eScript allows it.
*grins*
Posted: Fri May 05, 2006 12:27 pm
by Aeros
*Thinks of "ReleaseVariable(variable)" to release the var from the scope, and clear it as well*.
You never know...

Posted: Fri May 05, 2006 12:46 pm
by Yukiko
Yeah that's one possibility.
Alot of it depends on how good POL is at garbage collection too once a var is no longer needed. Ofcourse it would have to be out of scope for POL to know it was no longer needed.
Posted: Fri May 05, 2006 12:48 pm
by Aeros
Yeah.
Btw Yukiko, my forum messenger seems to be borked. Can you send me your contact details, need to talk to you bout something.
Posted: Fri May 05, 2006 1:01 pm
by Yukiko
Ny ICQ should ve on the forums but just in case it's 177-470-156.
email is
hopelivesproject@yahoo.com
Posted: Fri May 05, 2006 2:23 pm
by tekproxy
The reason I ask is because people that work on the core are doing it, and I was wondering if it really helped or not... Since eScript isn't a low level language I don't think people really need to care about releasing variables, or, at least I thought this until I saw it a number of times in the distro which was coded by people that know more than me and actually do know exactly how the core works.
Posted: Fri May 05, 2006 3:21 pm
by Austin
There really isnt an easy way to unset a variable in the core...
When you pass something to a script like an array, it is not passed as a reference, it is passed as a copy.
Then the array is broken back down and copied into meaningful variables.
SInce its no longer needed, I set it to 0 to take up less memory for the duration of the script. That memory is always used because it never goes out of scope until the script ends.
Its a mix of making the script easier to use, and using less memory.