Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Memory & Strings

Shifting Dreamscape
Always questioning ...
Join date: 12 Dec 2007
Posts: 266
10-02-2008 04:33
I am trying to write a script that will store some historic data. I have decided that since I know the exact data structure size, the most efficient way to store will be via a string.

My one question comes to the functions accessing the storage string. In a post on List memory (/54/27/174060/1.html the following was mentioned:

From: Deanna Trollop

However, remember that in order to access any data in a list, you have to pass a copy of that list to one of the llList2* functions, so you always have to keep as much memory free as is occupied by the list.


So should I assume that this holds the same for strings? i.e. if I call:

llSubStringIndex(ListStr, SearchStr);

And ListStr is 4k, does this mean I'll temporarily need another 4k of memory? Meaning as well then that if I have calculated I can store 160 elements in the string, I should really only store 80 to cover for calls to functions that require me to pass the ListStr?

Thanks!
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
10-02-2008 08:00
I believe (at least in LSO; not sure about Mono) it generally only adds memory to your script's ledger if the data is actually stored to a list/string variable. The exception seems to be that an assignment counts both the memory JUST prior to assigning to the variable and the memory used after the assignment. That's why this old hack works:

myList = (myList=[])+myList+[ ... ];
myString = (myString="";)+myString+"...";

It will ALWAYS need double the amount of memory in the SYSTEM to do the copy (you can't really escape that on a computer), but it is only marked against your script if it is stored in your SCRIPT variable right at the time of the assignment, not if it is merely needed in actual RAM.
bobbyb30 Swashbuckler
Registered User
Join date: 8 Sep 2008
Posts: 46
10-02-2008 17:12
From: Shifting Dreamscape
I am trying to write a script that will store some historic data. I have decided that since I know the exact data structure size, the most efficient way to store will be via a string.

My one question comes to the functions accessing the storage string. In a post on List memory (/54/27/174060/1.html the following was mentioned:



So should I assume that this holds the same for strings? i.e. if I call:

llSubStringIndex(ListStr, SearchStr);

And ListStr is 4k, does this mean I'll temporarily need another 4k of memory? Meaning as well then that if I have calculated I can store 160 elements in the string, I should really only store 80 to cover for calls to functions that require me to pass the ListStr?

Thanks!



itll need to be llSubStringIndex(ListStr + (ListStr="";),Search term);
_____________________
Large supporter and contributer of LSL Editor available at lsleditor.org
Shifting Dreamscape
Always questioning ...
Join date: 12 Dec 2007
Posts: 266
10-03-2008 01:14
bobbyb30 --- that code though would clear ListStr, which is not what I would want to do if I am serching for the position of a particular element in the datastrem. Sounds Like I will just have to limit myself to 1/2 of what could fit in the memory space.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
10-03-2008 09:45
I don't think mere calling of llSubStringIndex() should use up any additional memory at all. That's what I was implying with my first post. By all means test it though.
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
10-03-2008 13:27
From: Hewee Zetkin
... That's why this old hack works:

myList = (myList=[])+myList+[ ... ];
myString = (myString="";)+myString+"...";

It will ALWAYS need double the amount of memory in the SYSTEM to do the copy (you can't really escape that on a computer), but it is only marked against your script if it is stored in your SCRIPT variable right at the time of the assignment, not if it is merely needed in actual RAM.


The good news is that with Mono, we don't need to play this game any more! Yay!

At least, according to a few things I tried, where it makes a big difference for old LSL but doesn't make any difference for Mono.
_____________________
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
10-03-2008 14:43
In LSL lists and strings are immutable. LSL-LSO implements immutability by copying the value when it is pushed onto the stack. LSL-Mono implements immutability by producing new objects as needed (as a result of a function call or operation). The result of which is when ever you interact with a variable in LSO you need space to duplicate that variable's value. In Mono duplication is simply not necessary.

To give a practical example.
If you want to work with a 4k string in LSO, besides needing the initial 4k for the string you need an additional 4k if you wish to work with the string.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey