Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Script efficiency

Alicia Mounier
Registered User
Join date: 17 Oct 2005
Posts: 78
06-28-2007 16:16
How accurate is llGetFreeMemory? I've been working on a gun script where the main script is the only script that stays on and handles pretty much all the info passed to the other scripts such as the rez scripts. I get a number back varying between 1.1kbs to 900+ bytes left in the script memory. Is this bad? Will this make it where it'll draw alot of resources from a sim? lol, i dunno t'm just trying to make it where it's not a resource hog and does well in any class of server for a sim. Seems to fire nicely even if the sim is a class 2 server. There is alot of stuff in it like a bunch of true false integers, strings for anims that are repeated so I don't have to keep typing in all the anim names, just use a string that is set to the anim, sounds and such. I just want it to run at it's best and not be a major source of lag.
RJ Source
Green Sky Labs
Join date: 10 Jan 2007
Posts: 272
06-28-2007 16:26
It's not all that accurate, but it is the only estimate you really have as to how much memory a script is using. The worry with script memory usage is not sim impact. But the script will die with a memory error if you run out.

Anything below 1500, personally, makes me nervous.

A common alternative is to move some of your functions or data to a second script, which will run in parallel. Unless you can just better tighten your existing code to use less memory.
Alicia Mounier
Registered User
Join date: 17 Oct 2005
Posts: 78
06-28-2007 16:33
I guess for now it won't really run out of memory since most of the stuff is either true or false, on or off. No other stuff will be dormant and turned on just changed. it seems to stay constant with how much freemem is there even after changing options and such. Thanks for the reply.
Domino Marama
Domino Designs
Join date: 22 Sep 2006
Posts: 1,126
06-29-2007 01:22
llGetFreeMemory is accurate but it returns the peak memory usage not current usage. There are a lot of little tricks you can do to help use less memory. Particularly if you are using lists an easy one is to replace things like:

myList += [ "extra", "list", "items" ];

with

myList = ( myList = [] ) + myList + [ "extra", "list", "items" ];

/54/c1/88658/1.html has the majority of the techniques.
Milambus Oh
Registered User
Join date: 6 Apr 2007
Posts: 224
06-29-2007 08:25
If you use a string constant more than once, put it in a variable.

Hmm, what we really need is a Wiki page for memory usage tips, does one exist already?
Alicia Mounier
Registered User
Join date: 17 Oct 2005
Posts: 78
06-30-2007 06:01
lol, yes there is a wiki for this and also a long discussion that Domino Marama pointed out.
LSL Wiki : memory
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
06-30-2007 09:24
As to your question about whether this means your script will use more sim resources, it won't. Every script, no matter how simple, gets allocated exactly 16 kilobytes of simulator RAM to run in. It doesn't matter how much of it you actually use.
Galbraith Karami
Registered User
Join date: 12 Dec 2006
Posts: 25
07-02-2007 14:43
And as for the memory displayed, it is the current memory usage as far as I can tell, because I've seen it vary, lowering and raising, inside the executio of the same script, and without any reset.