Tipi di base

Utilizzate il metodo getSize() per valutare il codice e determinare l'oggetto più efficiente per un'operazione specifica.

Tutti i tipi di base eccetto String usano 4 – 8 byte di memoria. Non esiste un modo per ottimizzare la memoria utilizzando un tipo specifico per un tipo di base:

// Primitive types 
var a:Number; 
trace(getSize(a)); 
// output: 8 
 
var b:int; 
trace(getSize(b)); 
// output: 4 
 
var c:uint; 
trace(getSize(c)); 
// output: 4 
 
var d:Boolean; 
trace(getSize(d)); 
// output: 4 
 
var e:String;  
trace(getSize(e)); 
// output: 4

A un oggetto Number, che rappresenta un valore a 64 bit, vengono assegnati 8 byte dall'AVM (ActionScript Virtual Machine), se non viene assegnato un valore specifico. Tutti gli altri tipi di base vengono memorizzati in 4 byte.

// Primitive types 
var a:Number = 8; 
trace(getSize(a)); 
// output: 4 
 
a = Number.MAX_VALUE; 
trace(getSize(a)); 
// output: 8

Il comportamento è diverso per il tipo String. La quantità di memoria allocata dipende dalla lunghezza della stringa:

var name:String;         
trace(getSize(name)); 
// output: 4 
             
name = ""; 
trace(getSize(name)); 
// output: 24 
         
name = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularized in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";     
trace(getSize(name)); 
// output: 1172

Utilizzate il metodo getSize() per valutare il codice e determinare l'oggetto più efficiente per un'operazione specifica.