Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

String or List?

Flater Baxter
Registered User
Join date: 23 May 2007
Posts: 48
06-20-2007 10:53
I have made a script thats stores data, it also has to check it often.
what is the best way storing, it as a list, or as a string and calling it with a llCsv2List When I need it?

Thanks
Milambus Oh
Registered User
Join date: 6 Apr 2007
Posts: 224
06-20-2007 11:06
llCsv2List just returns a list, so its not going to be any more efficient then just storing the data as a list in the first place.

From what I have seen a List may be faster access speed wise, but they tend to be very inefficient in regards to memory usage.

So its going to depend on what exactly you are doing and how much data you wish to store.
Flater Baxter
Registered User
Join date: 23 May 2007
Posts: 48
06-20-2007 11:22
thanks for the fast reaction,

well I have to store key's, and I have to check them for doubles,
so its a high usage of memory. so every time a new key comes in I have to check the list.
list was my first choice till I was reading the forum about "light weight scripting" (it sounds like a new diet product:P )

Now I don't know whats best, If i do a llGetFreeMemory() the list comes of better, but I also read on the forum that that only gives the peaks....

thanks again so far!
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
06-20-2007 11:51
use a string and llSubstringIndex
AnnMarie Otoole
Addicted scripter
Join date: 6 Jan 2007
Posts: 162
06-20-2007 11:57
Storing and processing keys in a string is very clumsy and processor intensive while storing in a list make indexing very easy. However lists are memory hogs so depending on how much space your program occupies, you can rapidly run out of space with lists.

One trick I tried is to create a prim (or use any existing prim) for additional storage by doing llSay(-nnnnn,Data) and llListen(-nnnnn etc) to receive it. A similar reverse link will have the data storage prim send the already processed data result back when requested.

After a series of crashes I ended up moving the storage off SL to a web site with
llHTTPRequest(xxxxx). Now I have virtually unlimited and fast storage. Its still not perfect, you have to do some local storage and remote processing because you are limited to an AVERAGE of one HTTP request every 5 seconds. See http://rpgstats.com/wiki/index.php?title=ExamplellHTTPRequest for an example. If your lists are at all extensive this is the best solution but to stay within the traffic limits you will have to program the comparison searching etc., in php at the Internet location and just pass queries and results via the link because it is no good fetching 200 keys to search since they won't fit.
Flater Baxter
Registered User
Join date: 23 May 2007
Posts: 48
06-20-2007 16:11
Thanks man, That was Just where I was Looking for:))

"Returns the index in source where pattern first appears. Returns -1 if no match is found."
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
06-20-2007 19:30
From: AnnMarie Otoole
Storing and processing keys in a string is very clumsy and processor intensive


?

a key is really just a specialized string

its really no worse than processing a list, actually just a shade faster in most cases

and its probably less intensive because it doesnt have to keep track of index and whatever else is stored in those 40 extra bytes added to each element
Flater Baxter
Registered User
Join date: 23 May 2007
Posts: 48
06-21-2007 04:54
well I did some tests,
and if I'm not wrong (and I hope I'm not) in my case its better to use a list.

List test: 157 keys stored.
String test: 141 keys stored. (144 if I leave out the "'," )

but If I wanted to store a "4 letter word" i could better use a string;

List test "4 letters word" ,445 stored.
String test "4 letters word" , 1064 stored



//LIST TEST ://
integer total=0;
string a_key =" b7f5ef96-10eb-97b5-7e6c-67e847af7f6f";
list a_list;

default
{
touch_start(integer total_number)
{
llSay(0, (string)llGetFreeMemory() );
llSetTimerEvent(0.1);
}

timer()
{
total += 1;
a_list += a_key;
llSay(0,"KEY's Stored: "+(string)total+" Memory free: "+(string)llGetFreeMemory());
}
}
//////////end/////////

//STRING TEST//

integer total=0;
string a_key =" b7f5ef96-10eb-97b5-7e6c-67e847af7f6f";
string a_string;

default
{
touch_start(integer total_number)
{
llSay(0, (string)llGetFreeMemory() );
llSetTimerEvent(0.1);
}

timer()
{
total += 1;
a_string += a_key+",";
llSay(0,"KEY's Stored: "+(string)total+" Memory free: "+(string)llGetFreeMemory());
}
}
///////END////////
Milambus Oh
Registered User
Join date: 6 Apr 2007
Posts: 224
06-21-2007 09:29
May I introduce you to the mojo that is list concatenation:
a_list = (a_list = []) a_list + [a_key];

Using this instead of a simple += should save you quite a bit of memory.

http://lslwiki.net/lslwiki/wakka.php?wakka=list
Flater Baxter
Registered User
Join date: 23 May 2007
Posts: 48
06-21-2007 12:15
Thanks!!!!
(Y) ( a_list = (a_list = []) + a_list + [a_key]; ) = a nice trick (Y)
now I can store 329 keys :) on a list
and 439 keys on a string
// a_string= (a_string= "";) + a_string+ a_key; //