Jump to content

need help to reduce memory usage from Lists in a running LSL-Script


Xaver Roelofs
 Share

You are about to reply to a thread that has been inactive for 2106 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Greetings Members of Second Life

as the tittle says i need some help to reduce the memory usage of a Script.
The srcipt builds 6 Lists into Memory while the script runs. All six lists are building floating point number entries only.

The Script itself takes 37k memory. When the srcipt runs it builds a List wich is at least 11k and as you already had read, i need 6 Lists of them.

I tried to round up the floating point numbers and convert them into strings, but the lists consumung to much memory anyway. Is there a way to pack Lists in a running script? Any suggestions or idears or help is welcome.

Link to comment
Share on other sites

It may take a bit of work, but one common solution is to build and store your lists in a separate script. In fact, move any functions that need to sort or search the lists into the separate script as well, so that you simply pass the results back to the main script with link messages as they are needed. A modular approach like that can also have the advantage of clarifying some of the overall logic of your script.

Link to comment
Share on other sites


I tried to round up the floating point numbers and convert them into strings, but the lists consumung to much memory anyway.

The multiple-script approach Rolig describes is much more general and scalable than this, but just in case it's relevant: Global lists store rotations a lot more concisely than four floats : 28 bytes vs 16*4 = 64 bytes. See this wiki page for some user-collected measurements. 

If one of your lists of floats is about 11K, it must be about 688 elements long, so six of those would be about 4,128 total float elements -- which would fit in 1,032 rotations, and a list of that many rotations should be a little under 29K. That won't quite fit in 64K if the script itself is 37K, but it's mighty close. Of course the script would have to get somewhat more complex to calculate the list index for the rotation, and then the component  of the rotation to use for the float.

Link to comment
Share on other sites

Greetings..

 

** it must be about 688 elements long, **

i didnt count it, but can be true such huge amount of elements for each List. Its a interesting idear to build rotations from floats, if this methode safes the memory usage. I will try out and see...

I think, to outsource the Lists into additional Scripts is the safest Methode that'll work. Thank you for your Idears and help.

 

 

Link to comment
Share on other sites

Not really all that more complex to do lookups if an element is buried in a rotation.  Say you want the 27th element in a list:

There's 4 "elements" to a rotation, so...

27 / 4 = 6 with 3 remainder, so you read the next element (7th element out of the list) into a rotation, and grab the 3rd value (rot.z), a bit more complex than a straight lookup, but not that difficult to work around.  That's a great method to pack a large number of floats using rotations in a case like this.

 

Ok, got to wondering how to code it out, this is what I came up with, it can probably be written tighter, but this is what I came up with... works with 1 as the first list element returning the first entry in the list (not 0).

list listOfFloats = [<1.1,1.2,1.3,1.4>,<2.1,2.2,2.3,2.4>,<3.1,3.2,3.3,3.4>];integer elementToGet = 12;float finalElement;default{    state_entry()    {        integer listElement = (integer)(elementToGet / 4);        integer rotElement = elementToGet % 4;        if (rotElement == 0)        {            listElement -=1;        }        rotation rot = llList2Rot (listOfFloats, listElement);        if (rotElement == 0)        {            finalElement = rot.s;        }        else if (rotElement == 1)        {            finalElement = rot.x;        }        else if (rotElement == 2)        {            finalElement = rot.y;        }        else if (rotElement == 3)        {            finalElement = rot.z;        }        llOwnerSay ("Final Element: " + (string)finalElement);    }}
Link to comment
Share on other sites

-

i have no static lists that i build. The lists are empty when the script starts and gets their values from a object. The Object changes randomly those values.

The amount of values can also vary, while the script is running. When i take a snapshot (!!) of that hight amount of values it takes a time of 15 seconds, so there is not much space for any delay.

-

Link to comment
Share on other sites

Just in case it's helpful: For some applications, nothing like 32-bit floating-point precision is needed. For example, I've written some SL region map-related scripts that really only need to be accurate to the nearest meter, and regions are only 256m x 256m. A single 32-bit integer can store four of those eight-bit numbers for two X,Y pairs to one-meter precision, or one X,Y pair to 1/256m precision, or an X,Y,Z triple to... umm... 1/ 4 m precision I guess, with a couple bits to spare.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2106 days.

Please take a moment to consider if this thread is worth bumping.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...