PHP Kernel Tour-4. Variable-length strings

Source: Internet
Author: User

PHP Kernel Tour Series

PHP Kernel Tour-1. Life cycle

PHP Kernel Tour -2.sapi CLI

PHP Kernel Tour-3. Variables

PHP Kernel Tour-4. String

First, the string source code

Zend_string

1typedefstruct_zend_string zend_string;//Defining zend_string Variables2 struct_zend_string {//_zend_string Structural Body3 Zend_refcounted_h GC;4Zend_ulong h;/*Hash Value*/5 size_t Len;6     Charval[1];7};

Variable Describe
1
Gc
Variable reference count information, memory management will use the
2
H
Harh code, the string is computed by the TIMES33 algorithm.
3
Len
The length of the string
4
VAL[1]
The contents of the string
Second, the string structure

Attention:

1. zend_string = reference count + String hash code + string length + string content.

2. The string Val is a mutable array, and val[1] means that the string terminator is held by default.

3. Val[0] Stores an empty string. When the string is not empty, val[0 ~ Len] holds the string contents. Val[len+1] = ' 0\ '

For example, the ' test ' string is stored in this way:

Val[0] = ' t '

VAL[1] = ' e '

VAL[2] = ' s '

Val[3] = ' t '

VAL[4] = ' + ' string terminator

PHP Kernel Tour-4. Variable-length strings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.