Difference between revisions of "LSL Constants vs Globals"

From Second Life Wiki
Jump to navigation Jump to search
(New page: There are some advantages in using global variables over the string and key constants, it's faster and uses less bytecode when it is longer then 3 characters and it used more then twice bu...)
 
Line 1: Line 1:
There are some advantages in using global variables over the string and key constants, it's faster and uses less bytecode when it is longer then 3 characters and it used more then twice but it uses more bytecode when it is shorter then 3 characters or it used once. This is easily demonstrated by running the scripts in Figure 2.
There are some advantages in using global variables over the string and key constants, it's faster and uses less bytecode when it is longer then 3 characters and it used more then twice but it uses more bytecode when it is shorter then 3 characters or it used once. This is easily demonstrated by running the scripts in Figure 2.


{| {{Prettytable|style=margin-top:0;}}
===Pros===
|+ Figure 1: Pros and Cons of using globals
|- {{Hl2}}
! Constant
! Global
|- valign="top"
|
* Faster
* Faster
* Uses less bytecode when it is longer then 3 characters and it used more then twice.
* Uses less bytecode when it is longer then 3 characters and it used more then twice.
|
===Cons===
* Uses more bytecode when it is shorter then 3 characters or it used once.
* Uses more bytecode when it is shorter then 3 characters or it used once.
|}


{| {{Prettytable|style=margin-top:0;}}
{| {{Prettytable|style=margin-top:0;}}

Revision as of 08:20, 8 July 2008

There are some advantages in using global variables over the string and key constants, it's faster and uses less bytecode when it is longer then 3 characters and it used more then twice but it uses more bytecode when it is shorter then 3 characters or it used once. This is easily demonstrated by running the scripts in Figure 2.

Pros

  • Faster
  • Uses less bytecode when it is longer then 3 characters and it used more then twice.

Cons

  • Uses more bytecode when it is shorter then 3 characters or it used once.
Figure 2: Bytecode Cost
Constant Global

<lsl>

dead(){

   key a = NULL_KEY;
   key b = NULL_KEY;
   key c = NULL_KEY;
   key d = NULL_KEY;

}

default {

   state_entry() {
       llOwnerSay(llGetFreeMemory());
   }

}</lsl>

<lsl>key null_key = NULL_KEY;

dead(){

   key a = null_key;
   key b = null_key;
   key c = null_key;
   key d = null_key;

}

default {

   state_entry() {
       llOwnerSay(llGetFreeMemory());
   }

}</lsl>