原始类型

使用 getSize() 方法为代码设置基准确定任务的最有效对象。

所有原始类型(String 除外)在内存中都是占用 4 – 8 个字节。使用特定类型的基元无法优化内存:

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

如果没有为表示 64 位值的数字分配值, ActionScript 虚拟机 (AVM) 将为其分配 8 个字节。所有其他原始类型存储时均占用 4 个字节。

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

此行为不同于 String 类型。分配的存储量基于 String 的长度:

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

使用 getSize() 方法为代码设置基准确定任务的最有效对象。