Jump to content

May you help me with a problem of memory ?


Miranda Umino

Recommended Posts

Hi , i ve got a problem of memory in a script and i don t understand what it happens .

I am very glad that in the Snack sims the function llGetUsedMemory has been released . So , i ve wanted to test my scripts

It s a simple script who allocates some memory every time and it frees the old memory when i  ve reached an amount of memory

when i write the function FIFO_free_memory with the line "llOwnerSay("free called");"  commented , the script reaches a stack heap error collision

when i write the function FIFO_free_memory with the line "llOwnerSay("free called");"  uncommented , the script runs until i stop it in touching a second time

list l ; // it s my FIFO list , i will add some elements on it .. and when i reach too much memory , i will delete the first elements inputed
integer i =0; // a counter to know how many allocations i have done
integer start; // a boolean to start and stop the script

// Function to free the memory
list FIFO_free_memory(list  l)
{
    // i am allocating 7 per 7 elements each time . So i m deleteing  the 7 firsts elements
    //llOwnerSay("free called");
    return llDeleteSubList(l, 0, 6) ;
}
list FIFO_add_memory( list l)
{
    // i add 7 elements ( the firsts are just to make grow teh memory faster . The counter at the end will inform me which element i ve reached
    return l +  [ llGetKey(), llGetOwner(),llGetKey(), llGetOwner(), llGetKey(), llGetOwner(), i++ ];
}
default
{
    state_entry()
    {
        // initialize start
        start = TRUE;
    }

    touch_start(integer total_number)
    {
        // the first time i touch the prim  i run the timer 
        // the second time i stop the script and restart it to be sure to have not clean memory between two runs
        if (start)
        {
            start = FALSE ;
            llSetTimerEvent(0.25);
        }
        else
             llResetScript();
    }
    timer()
    {
        // i display the memory used and the top of the stack
        llOwnerSay("Timer Memory used =" + (string)llGetUsedMemory()  + " SP="+(string)llGetFreeMemory()  );

        // if i ve used more 40kbytes , i start to desallocate before to allocate
        if ( llGetUsedMemory() > 40000 )
        {
            l = FIFO_free_memory(l);
            // i display  number elements in the list the 1st value of the counter  and the last value of the counter
            llOwnerSay("Number elements =" + (string)llGetListLength(l)+ " 1st=" + llList2String(l,6) + " last="+llList2String(l,-1) );
        }
        l = FIFO_add_memory(l);
        
    }
}

 

When the script runs without stack heap error collision , it displays

...
...
[18:43] Object: Timer Memory used =37792 SP=27744
[18:43] Object: Timer Memory used =38420 SP=27116
[18:43] Object: Timer Memory used =39048 SP=26488
[18:43] Object: Timer Memory used =39676 SP=25860
[18:43] Object: Timer Memory used =40304 SP=25232
[18:43] Object: free called
[18:43] Object: Number elements =364 1st=1 last=52
[18:43] Object: Timer Memory used =40352 SP=25232
[18:43] Object: free called
[18:43] Object: Number elements =364 1st=2 last=53
[18:43] Object: Timer Memory used =40304 SP=25232
[18:43] Object: free called
[18:43] Object: Number elements =364 1st=3 last=54
[18:43] Object: Timer Memory used =40304 SP=25232
[18:43] Object: free called
[18:43] Object: Number elements =364 1st=4 last=55
[18:43] Object: Timer Memory used =40304 SP=25232
[18:43] Object: free called
[18:43] Object: Number elements =364 1st=5 last=56
[18:43] Object: Timer Memory used =40304 SP=25232
[18:43] Object: free called
...
...
and so on , it continues without break

 

When it s stopped by a stack heap error collision i ve displayed

[18:47] Object: Timer Memory used =37164 SP=28372
[18:47] Object: Timer Memory used =37792 SP=27744
[18:47] Object: Timer Memory used =38420 SP=27116
[18:47] Object: Timer Memory used =39048 SP=26488
[18:47] Object: Timer Memory used =39676 SP=25860
[18:47] Object: Timer Memory used =40304 SP=25232
[18:47] Object: Number elements =364 1st=1 last=52
[18:47] Object: Timer Memory used =40352 SP=25232
and  one stack heap error collisiion there

 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...