Efficient use of variables?

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.
Post Reply
User avatar
tekproxy
Forum Regular
Posts: 352
Joined: Thu Apr 06, 2006 5:11 pm

Efficient use of variables?

Post 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. :(
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

Post 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*
Aeros
Journeyman Poster
Posts: 69
Joined: Mon Apr 24, 2006 10:56 am

Post by Aeros »

*Thinks of "ReleaseVariable(variable)" to release the var from the scope, and clear it as well*.

You never know... :P
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

Post 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.
Aeros
Journeyman Poster
Posts: 69
Joined: Mon Apr 24, 2006 10:56 am

Post 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.
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

Post by Yukiko »

Ny ICQ should ve on the forums but just in case it's 177-470-156.

email is hopelivesproject@yahoo.com
User avatar
tekproxy
Forum Regular
Posts: 352
Joined: Thu Apr 06, 2006 5:11 pm

Post 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.
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Post 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.
Post Reply