9 janvier 2011

LSL : Scripts et mémoire

English version

Pour reprendre un peu l'esprit du précédent post sur l'analyse des katanas C:SI en regard du nombre de script et de mémoire allouée, plusieurs petits point de réflexion.

Je peux avoir un objet avec un seul script qui consomme beaucoup de mémoire. Par exemple : je définis une liste et mon script ajoute des valeurs à cette liste... Les valeurs étant stockées dans le script, sa taille va augmenter.

Pour plus d'information sur la mémoire consommée : http://wiki.secondlife.com/wiki/LSL_Script_Memory

De la même manière un petit script peut être très gourmand en temps processeur.

On parle beaucoup en ce moment dans le petit monde du C:SI de détection du nombre de scripts et de mémoire allouée, mais n'oublions pas q'un script gourmand en mémoire peut consommer peut de temps processeur sim, et qu'un petit script peut être une grosse usine a gaz.

La notion de nombre de script, mémoire allouée, est juste une indication.

Essayer de définir des limites raisonnables peut parfois être une erreur.
Pour tout ceux qui veulent approfondir la chose, voici un petit script tout simple. A placer dans un objet. Quand on clique dessus, il donne le nom de l'avatar, le nombre de scripts dans les objets portés et la mémoire allouée pour tout cela.

Il s'appuie sur la fonction suivante : llGetObjectDetails
Pour obtenir les infos souhaitées, je lui passe en paramètres : OBJECT_RUNNING_SCRIPT_COUNT et OBJECT_SCRIPT_MEMORY

Voici le code :


default {

touch_start(integer total_number) {
list infos = llGetObjectDetails(llDetectedKey(0),[OBJECT_RUNNING_SCRIPT_COUNT,OBJECT_SCRIPT_MEMORY]);

//avatar name
string msg = llDetectedName(0);

// Scripts count
msg += " - " + llList2String(infos, 0) + " scripts - " ;

// memorry allocated
msg += (string)((integer)llList2String(infos, 1) / 1024) + " Ko";

// display all informations
llSetText(msg, <1.0,1.0,1.0>, 1.0);
}
}








English version (quick and not litteral translation)

To continue previous post on analysis of C: SI katanas compared to the number of script and memory allocated, several small reflections.

I can have an object with a single script that consumes lots of memory. For example: I define a list and my script adds values to this list ... The values are stored in the script, its size will increase.

For more information about memory consumption : http://wiki.secondlife.com/wiki/LSL_Script_Memory

Similarly, a small script can be very CPU-intensive.

In the small world of C: SI, there is much talk now about detecting how many script you wear and allocated memory.
But do not forget that a heavy memory script can be low lag, and a little script can use lot's of CPU time.

The concept of a number of scripts, allocated memory, is just an indication.

Try to set reasonable limits can sometimes be a mistake.

I give you a simple script. Place in an object. When clicked, it gives the name of avatar, number of scripts and the memory allocated .

It is based on the following function: llGetObjectDetails
To obtain the desired information, I use this parameters : OBJECT_RUNNING_SCRIPT_COUNT and OBJECT_SCRIPT_MEMORY

Here's the code:


default {

touch_start(integer total_number) {
list infos = llGetObjectDetails(llDetectedKey(0),[OBJECT_RUNNING_SCRIPT_COUNT,OBJECT_SCRIPT_MEMORY]);

//avatar name
string msg = llDetectedName(0);

// Scripts count
msg += " - " + llList2String(infos, 0) + " scripts - " ;

// memorry allocated
msg += (string)((integer)llList2String(infos, 1) / 1024) + " Ko";

// display all informations
llSetText(msg, <1.0,1.0,1.0>, 1.0);
}
}

Enjoy, use, modifiy, adapt it....

Aucun commentaire: