Unofficial LSL reference

User Tools

Login

You are currently not logged in! Enter your authentication credentials below to log in. You need to have cookies enabled to log in.

Login

Forgotten your password? Get a new one: Set new password

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

types:list [2017-09-20 11:46 SLT]
sei
types:list [2021-02-01 09:00 SLT] (current)
sei Info on passing lists by reference
Line 118: Line 118:
 This list takes only 20 bytes (16 for the integer and 4 for a reference to the same integer). This list takes only 20 bytes (16 for the integer and 4 for a reference to the same integer).
  
-Strings in particular can also be reused if they already exist in some variable, as long as they are not the result of some operation ($lfn[llList2String] is not considered an operation, but addition of strings and other functions such as $lfn[llToLower],​ $lfn[llGetSubString],​ etc. are). If they are the result of some operation, they are not reused, but they are reusable. For example:+Strings in particular can also be reused if they already exist in a list, as long as they are not the result of some operation ($lfn[llList2String] is not considered an operation, but addition of strings and other functions such as $lfn[llToLower],​ $lfn[llGetSubString],​ etc. are). If they are the result of an operation, they are not reused, but they are reusable. For example:
  
 <code lsl2> <code lsl2>
Line 124: Line 124:
 list A = (list)"​X";​ list A = (list)"​X";​
 // This only adds 4 bytes to the list, because constant // This only adds 4 bytes to the list, because constant
-// strings are reusable ​if they have been used +// strings are reused ​if they have been used 
-// to assign them to some variable or list element +// to assign them to some list element ​that 
-// that still contains the unmodified string, in +// still contains the unmodified string, in this 
-// this case the first element of the list:+// case the first element of the list:
 A += "​X";​ A += "​X";​
-// This adds 18 bytes to the list because the+// This adds 20 bytes to the list because the
 // string that results from a calculation is not // string that results from a calculation is not
 // reused, even if it matches an existing // reused, even if it matches an existing
Line 138: Line 138:
 A = A + llList2String(A,​ -1); A = A + llList2String(A,​ -1);
 string B = "​Y";​ string B = "​Y";​
-// This adds bytes to the list, because the +// This adds 20 bytes to the list
-// string already exists in B:+A += B; 
 +// This adds 4 bytes to the list:
 A += B; A += B;
-// This adds 20-4=16 bytes to the list because 
-// the string "​X"​ ceased to exist in B: 
-B = "";​ 
 </​code>​ </​code>​
  
-Basically, the rule isn't whether the strings are equal, but whether they are handled verbatim without applying operations to them. The same trick doesn'​t work with keys, though.+Basically, the rule isn't whether the strings are equal, but whether they are handled verbatim without applying operations to them. The same trick fails with other types, including ​keys; adding e.g. a key variable to a list multiple times, results in one new instance of the key being counted for every addition. Same happens for integers, for example. But extracting them as lists still works. 
 + 
 +Lists are passed by reference to functions, meaning that when passing a list to a function, a new copy is not createdbut instead the same list is used.
  
 === Limits === === Limits ===
Line 153: Line 153:
  
   * List initializers are limited to 4096 elements.   * List initializers are limited to 4096 elements.
-  * List constructors are limited by an internal stack limit on expressions. The stack limit is 1024, but some of it is used internally and while doing operations, ​and you can't use a list constructor with more than 1022 elements and assign it to a variable. +  * List constructors are limited by an internal stack limit on expressions. The stack limit is 1024, but part of it is used internally and while doing operations, ​so you can't use a list constructor with more than 1022 elements and assign it to a variable. 
-    * This same stack limit affects any kind of expression, not just list constructors. It would be too hard to describe how stack is used by expressions,​ but you can work around the limit by breaking up the expression ​into several assignments.+    * This same stack limit affects any kind of expression, not just list constructors. It would be too hard to describe how the stack is used by expressions,​ but if you really have an expression that complex, ​you can work around the limit by breaking ​it up into several assignments.