2012-11-01 61 views
0

我正在深入瞭解PHP的基礎知識,突然想到了「在哪種內存格式中變量存儲在內存中?」變量存儲在哪種內存格式中?

這是一個堆棧還是堆?

請我研究這個內存變量分配的參考材料..

+0

你說的「格式化」的意思是,你能不能做一個例子嗎? –

+0

現在你說「內存類型」是什麼意思? –

回答

3

PHP使用zval/pval作爲基本數據容器。

struct _zval_struct { 
    zvalue_value value;  // The value 
    zend_uint refcount__gc; // The number of references to this value (for GC) 
    zend_uchar type;  // The type 
    zend_uchar is_ref__gc; // Whether this value is a reference (&) 
}; 

typedef union _zvalue_value { 
    long lval;    // For integers and booleans 
    double dval;    // For floats (doubles) 
    struct {     // For strings 
     char *val;   //  consisting of the string itself 
     int len;    //  and its length 
    } str; 
    HashTable *ht;   // For arrays (hash tables) 
    zend_object_value obj; // For objects 
} zvalue_value; 

它們在zend.h定義:http://lxr.php.net/xref/PHP_5_4/Zend/zend.h#318