php internal - zend_string

php7内部string实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
typedef struct _zend_refcounted_h {
uint32_t refcount; /* reference counter 32-bit */
union {
struct {
ZEND_ENDIAN_LOHI_3(
zend_uchar type,
zend_uchar flags, /* used for strings & objects */
uint16_t gc_info) /* keeps GC root number (or 0) and color */
} v;
uint32_t type_info;
} u;
} zend_refcounted_h;

typedef struct _zend_string zend_string;

struct _zend_string {
zend_refcounted_h gc;
zend_ulong h; /* hash value */
size_t len; /* 字符串长度 */
char val[1]; /* 并非长度并非1字节,便于使用且比使用 char * 减少一次内存分配 */
};