Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Need to understand this 2 line of codes

elitesamster Fallen
Registered User
Join date: 30 Nov 2009
Posts: 5
11-30-2009 10:24
Hello everyone, please help me understand the codes below:


if (llGetListLength(okList) >= 1800) {
okList = llDeleteSubList(okList, 0, 200);


These 2 line of codes meaning if the list is over 1800 sec than auto delete? and the llDeleteSubList(okList, 0, 200); meaning delete the end 200 elements?


Thank you
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
11-30-2009 10:27
From: elitesamster Fallen
Hello everyone, please help me understand the codes below:


if (llGetListLength(okList) >= 1800) {
okList = llDeleteSubList(okList, 0, 200);


These 2 line of codes meaning if the list is over 1800 sec than auto delete? and the llDeleteSubList(okList, 0, 200); meaning delete the end 200 elements?


Thank you

Yes and no.

llGetListLength() returns an integer number that is the total number of list entries in the specifed list (okList) in this case.

According to the code, if the list grows to 1800 (or more) entries, then...

llDeleteSubList (okList, 0, 200) means delete the first entry (entry 0) to the 201's entry (entry 200).

Lists typically grow from the first entry on by some other code adding on to the list. This means that the older entries are at the beginning, which is why those entries are being deleted.

Hope that helps.
elitesamster Fallen
Registered User
Join date: 30 Nov 2009
Posts: 5
11-30-2009 10:40
From: Johan Laurasia
Yes and no.

llGetListLength() returns an integer number that is the total number of list entries in the specifed list (okList) in this case.

According to the code, if the list grows to 1800 (or more) entries, then...

llDeleteSubList (okList, 0, 200) means delete the first entry (entry 0) to the 201's entry (entry 200).

Lists typically grow from the first entry on by some other code adding on to the list. This means that the older entries are at the beginning, which is why those entries are being deleted.

Hope that helps.


I understand better now thank you, so if I want to delete the whole 1800 entries I should do llDeleteSubList (okList, 0, 1800)?

How big the list can hold? I mean just for avatar names.

Thanks
Nyx Alsop
Registered User
Join date: 14 Dec 2008
Posts: 252
11-30-2009 11:24
if (llGetListLength(okList) >= 1800) {
okList = llDeleteSubList(okList, 0, llGetListLength(okList));
}
elitesamster Fallen
Registered User
Join date: 30 Nov 2009
Posts: 5
11-30-2009 11:29
From: Nyx Alsop
if (llGetListLength(okList) >= 1800) {
okList = llDeleteSubList(okList, 0, llGetListLength(okList));
}



Thank you :)
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
11-30-2009 11:35
From: Nyx Alsop
if (llGetListLength(okList) >= 1800) {
okList = llDeleteSubList(okList, 0, llGetListLength(okList));
}

Or just a "okList = [];" will nuke the whole list.
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
11-30-2009 12:08
Or, to complete the thought, you can remove elements from the end of the list by using negative indices. So ....

llDeleteSubList(okList, -201, -1);

removes the last (i.e., the most recent) 200 entries in the list.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
elitesamster Fallen
Registered User
Join date: 30 Nov 2009
Posts: 5
11-30-2009 12:11
Great! Thanks alot for the replies :). But can anyone tell me how big capacity can the list hold before it crash?
Pete Olihenge
Registered User
Join date: 9 Nov 2009
Posts: 315
11-30-2009 12:14
CODE
okList = [];


should clear the list without the overhead of passing a duplicate of the list to the llDeleteSubList function.

How many names will a list hold? As this is something I'll need to look at sometime soon, I tried an experiment with ths script:

CODE
list my_list = [];
integer count = 0;

default
{
state_entry()
{
while (TRUE)
{
my_list += "123456789012345678901234567890123456";//36 characters max for an SL name
llOwnerSay ((string) (++count));
}
}
}


The result is rather puzzling. The mono compiled version reached 7758 before the stack/heap collision, but the LSL compiled one only made it to 163. I had expected the LSL version to manage about a quarter of the size of the mono one, given that mono scripts have 64K of memory to play with compared to 16K for LSL. Can someone explain what's happening?

Two further points: as I understand it function parameters are passed by value, that is, a duplicate of the original list is created and passed to the function to work on, so a useable list can only use (less than) half of the available memory in order to acommodate the duplicate. Also, I've seen it suggested here that for non-life-critical applications it's usually adequate to store only the first eight characters of the key, converted from a hexadecimal string to an integer, giving a considerable increase in storage capacity.

But I am rather new to this game, so most of this post is probably wrong.

EDIT: by "game" I mean "scripting game" - I would never dare describe SL as a "game".
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
11-30-2009 12:18
From: Pete Olihenge
The result is rather puzzling. The mono compiled version reached 7758 before the stack/heap collision, but the LSL compiled one only made it to 163. I had expected the LSL version to manage about a quarter of the size of the mono one, given that mono scripts have 64K of memory to play with compared to 16K for LSL. Can someone explain what's happening?

What do you get if you do...

my_list = (my_list = []) + my_list + "big string";

...instead?
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Pete Olihenge
Registered User
Join date: 9 Nov 2009
Posts: 315
11-30-2009 12:23
It made it to 334 using that code. Better, but still puzzling.

EDIT: looking again at the numbers, I realise that the really puzzling thing is that the mono compiled version appears to be storing in excess of 200K (7758 * 36) bytes of data in a memory space of 64K.

Wondering if the mono compiler was optimising my use of a string literal, I tried again using llFrand to generate the first 32 characters of a dummy name:

my_list = (my_list = []) + my_list + (string) llFrand (1.0) + (string) llFrand (1.0) + (string) llFrand (1.0) + (string) llFrand (1.0) + "1234";

Result: LSL 159, mono 378. This is closer to what I'd've expected. I'm going to guess that one of the reasons that mono scripts have a 64K memory allocation is that they use a lot more memory for overheads, hence only a doubling of storage capacity for a four-fold increase in storage space.

Does this make sense?
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
11-30-2009 16:35
I've stuffed 300+ keys in a list under LSO, and 500+ in MONO, but you also have to be aware of script overhead for other running code, so it'll vary if there's a lot of other code, but those are good safe upper limits for relatively small amounts of other code.

the reason for deleting the first xxx number of entries in a list is to preserve the most recent ones (if adding to the end) while keeping the script from running out of memory. you don't want to take off from the end unless you add your new entries to the beginning (which can be helpful if you are searching recent entries). all assuming that it's the most recent entries you care about... if it's the originals, then the logic is reversed
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -