Tipos primitivos

Use o método getSize() para criar um benchmark do código e determinar o objeto mais eficiente para a tarefa.

Todo os tipos primitivos, exceto String, usam 4 – 8 bytes de memória. Não há como otimizar a memória usando um tipo específico para um primitivo:

// 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

Um Número, que representa um valor de 64 bits, tem 8 bytes a ele alocados pelo ActionScript Virtual Machine (AVM), caso um valor não lhe tenha sido atribuído. Todos os outros tipos primitivos são armazenados em 4 bytes.

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

O comportamento difere para o tipo String. A quantidade de armazenamento alocada se baseia no comprimento da sequência de caracteres:

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

Use o método getSize() para criar um benchmark do código e determinar o objeto mais eficiente para a tarefa.