Difference between revisions of "LSL Script Memory/es"

From Second Life Wiki
Jump to navigation Jump to search
Line 130: Line 130:


==Llamando funciones==
==Llamando funciones==
21 bytes to call a function with no return<br>
21 bytes para llamar a una función sin retorno<br>
21 bytes to call a function with any return + type of return<br>
21 bytes para llamar a una función con cualquier retorno + tipo de retorno <br>
Subtract number of parameters entered
Reste el número de parámetros ingresados
===Tipos de Retorno===
===Tipos de Retorno===
integer  2
integer  2
Line 141: Line 141:
rotation 2
rotation 2
list    18 + lista de uso de memoria
list    18 + lista de uso de memoria
==Ejemplos==
==Ejemplos==
<pre>
<pre>

Revision as of 12:56, 6 March 2008

Memoria de Script

Todos los scripts en LSL comienzan con 16 kilobytes de memoria y esa memoria se usa rápidamente. Abajo esta una lista de código y uso de memoria.

Todos los datos a continuación fueron compilados usando llGetFreeMemory(). Como el compilador de LSL no es un programa simple, los datos abajo pueden no ser 100% correctos. De hecho, parte de el es incorrecto y necesita correciones.

There are still many bits that can be improved upon, and many more that can be taken into more detail. If anyone has any free time and doesn't know what to do, play around with the memory usage for different functions. A list of needed updates can be seen at the end of the page.

Variables

Declarando variables como globales

Uso de Memoria de Variables

integer  10
float    10
string   18 + 1 por carácter
key      18 + 1 por carácter
vector   18
rotation 22
list     21 + lista de uso de memoria

Lista de Uso de Memoria

integer  15
float    15
string   12 + 1 por carácter
key      12 + 1 por carácter
vector   23
rotation 27
list     Las Listas no pueden contener otras listas

Declarando variables dentro del estado predeterminado

Uso de Memoria de Variables

integer  15
float    15
string   12 + 1 por carácter
key      12 + 1 por carácter
vector   31
rotation 39
list     15 + list memory usage

Lista de Uso de Memoria

integer  7
float    7
string   4 + 1 por carácter
key      4 + 1 por carácter
vector   23
rotation 30
list     Las Listas no pueden contener otras listas

Simplemente declarando valores

Colocando un Valor en la Pila (Stack)

Integers 1 + 4 bytes para el valor
Float    1 + 4 bytes para el valor
String   1 + bytes por carácter + 1 byte para nulo
Key      1 + bytes por carácter + 1 byte para nulo
Vector   1 + 3 * float cost
Rotation 1 + 4 * float cost
List     1 + 4 para la longitud de la lista + uso de lista de memoria

Remover un valor de una pila cuesta 1 byte.

Lista de Uso de Memoria

Integers 7
Float    7
String   4 + 1 por carácter
Key      4 + 1 por carácter
Vector   23
Rotation 30
list     Las listas no pueden contener listas

Constantes

Todas las contantes de numero entero usan 6 bytes de memoria.

Otras Constantes

ZERO_VECTOR   16
ZERO_ROTATION 21
NULL_KEY      39

Extras

6 bytes para variables de referencia

Ejemplos

integer i; //10 bytes

default {
 state_entry() {
  list l = ["Testing", "This"] //15 (list) + 15 (string) + 8 (string)
 }
}

Funciones

Declarando funciones

Las funciones requieren 16 bytes para crearse con 3 bytes por parámetro, además del tipo de retorno.

Tipos de retorno

integer  4
float    4
string   4
key      4
vector   20
rotation 27
list     4

Declarando variables en funciones

Uso de Memoria de Variables

integer  11
float    11
string   8 + 1 por carácter
key      8 + 1 por carácter
vector   19
rotation 23
list     11 + lista de uso de memoria

Lista de Uso de Memoria

integer  7
float    7
string   4 + 1 por carácter
key      4 + 1 por carácter
vector   23
rotation 30
list     Las listas no pueden contener listas

Llamando funciones

21 bytes para llamar a una función sin retorno
21 bytes para llamar a una función con cualquier retorno + tipo de retorno
Reste el número de parámetros ingresados

Tipos de Retorno

integer 2 float 2 string 10 + 1 por carácter devuelto key 10 + 1 por carácter devuelto vector 2 rotation 2 list 18 + lista de uso de memoria

Ejemplos

list f() {  //16 (function) + 4 (return)
    list ret = [0]; //11 (list) + 7 (integer)
    return ret; 6 (list)
}  
string f() {
    return "";
}

default {
    state_entry() {
        f();   //21 (call to f) + 10 (returns string)
    }
}

Operators

List of Operators

+  1
-  1
*  1
/  1
%  1
&  0
|  0
^  0
!  0
>> 0
<< 0
~  1
== 1
<= 1
<  1
>= 1
>  1
!= 1

Assignment

Assigning values to variables takes as many bytes as used minus one.

Examples

string s; //12 bytes
s;        //6 bytes
"";       //3 bytes (see below)
s = "";   //8 (6 (string) + 3 (null string) - 1) bytes

However...

string s = ""; //12 bytes
integer i; //15 bytes
i = i + 1 // 6 bytes (integer) + 6 bytes (integer) + 6 bytes (1) + 1 byte (addition) - 1 byte (assignment)

Statements

if    6
while 11
for   11
do    6
jump  5
@     0
state 5

Examples

if (5 < 10) { // 6 (if) + 6 (integer) + 6 (integer) + 1 (compare)
//Do something here
}
while (1 < 2 & 3 < 4) { // 11 (while) + 4*6 (4 integers) + 2 (2 compares)
//Do something here
}

Typecasting

integer  10
float    10
string   10
key      10
vector   10
rotation 10
list     25

Estados

14 bytes for any event in a state + 1 for each parameter 17 bytes to create a new state

Needed Updates

Several updates are needed for this page, the most needed are listed below:

  • Verification of all data
  • Clarification of explanations
  • Investigations into how the functions work
    • Calling of functions
    • How return types effect the return
  • In the following code, the call to llGetFreeMemory() returns a different value. How is it affected? Why?
default {
     state_entry() {
          llOwnerSay((string)llGetFreeMemory());
          list l = ["", "", "", ""];
          llOwnerSay((string)llGetFreeMemory());
     }
}