变量存储在哪种内存格式中?

时间:2012-11-01 07:15:52

标签: php

我正在深入研究PHP的基础知识,并突然想到“在哪种内存格式中变量存储在内存中?”

这是堆栈还是堆?

请提供一个参考资料,以便在内存中研究这个变量分配。

1 个答案:

答案 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