jeudi 28 juin 2007

Help!

Stack Heap error!

Five March’s scripts were attacked by this Stack Heap error several times. Documentation is available but not readily found. But while searching the internet Five found the game ‘Fishing’, which was well worth the detour. At last documentation about this error can be found simply on the documentary site about Linden script. ( http://slhomepage.com/lsl/StackHeapCollision.htm )

Each (Linden or LSL-) script has 16 K of memory available, which is eaten on two sides: the stack, and the heap. When these two monsters meet, no memory is left and an error is produced. After the error the script is not running any more, it is halted. The problem is that it is not verifiable if a script is running or not, from the script itself.

Of course 16K is really not much, when compared to the memory of computers nowadays. But even compared to the old Commodore 64, with 64K of memory, this isn’t much. And furthermore the memory is eaten much faster than in the Commodore 64K.
One help is available, but only with a running script: llGetFreeMemory(). This function can communicate the free memory, the least free memory ever, after compiling the script.

For testing this function should be used to check how much memory is used.
So every script of Five, in danger of having no memory, must be tested with this function.
With simple scripts, one can see how much memory is occupied by example a string of a list.

Try it out, adding a global string, or list.
Apparently these strings and lists are really devouring the available space. When running out of memory, the solution is to split the functionality of the script in two (or more parts). One script sending a message to the second script, which also has 16K of memory at its disposition.
In case of the script communicating with an external dBase, the memory is further occupied.
Some testing shows this:
The default script, with llSay(0,(string)llGetFreeMemory()); in the touch_start: 16048 free,

With one global string only declared: 16030
testString = "hello avatar"; 15994
ten times this string: 15638
list, even only declared: 15617
myList = [1,2,3,4,5,6,7]; mem = 15336
myList = [testString,testString,testString,testString,testString]; 14705
double the content of this list this list: 13230
adding a local list copying the global one: 12444

So playing around with a list and a string can eat 25% of the memory of a script.
On the other hand, the recording Microphone, which can be found in the DevShed, leaves about 13000 KB free, while doing HTTP request and returning 15 chatlines…..

When a script produces an error, it stops. No function is around to test if a script has stopped, so how to know this?
The solution is inserting a second script. The second script asks the first one: are you still awake? And when no answer is returned by the first script, the second script sends an email (or IM) to the owner: Help my brother has died!
So for instance in script one, the answer is seen to be sent, in the second, it is received...or not!!!




Aucun commentaire: