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-30 07:10 SLT]
sei Fix data memory handling related to variables
types:list [2021-02-01 09:00 SLT] (current)
sei Info on passing lists by reference
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 list element that // to assign them to some list element that
 // still contains the unmodified string, in this // still contains the unmodified string, in 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 144: Line 144:
 </​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 ===