NGINX data Structure--integer and string

Source: Internet
Author: User
NGINX Data structures – integers and strings

Considering the cross-platform, high efficiency, unified specification, Nginx encapsulates a lot of data structure, most of which we often use in other development projects, of course, there are some complex containers, the author of each article will be one to two points for analysis and practice explanation.

Integral package

typedef intptr_t ngx_int_t;typedef uintptr_t ngx_uint_t'

String type

In Nginx, the string is represented using ngx_str_t, which is defined as follows:

typedef struct {    size_t      len;    u_char     *data;} ngx_str_t;

We can see that it is a simple struct with only two members, the data pointer to the starting address of the string, and Len for the length of the string.
Here you may be wondering, the string in C can only be represented by a pointer, why does it need a length? This is because the C language we often say that the string, in fact, the "" "to the end of a string of characters, the Convention is commonly known, once read to this token is the end of the string, in C + + when the compiler will automatically add the '" \ "tag. However, the data pointer in ngx_str_t is not a string in the C language, but just a starting address for a string of ordinary characters, and the string does not specifically use the '/s ' tag as its own end, so we need Len to tell the user the length of the string.
What good would that do? As a Web server, Nginx of course more consideration of this convenient development needs, in the network request, we contact the most is the URL address, request header information, request entity, etc., take the URL address, such as user request:

GET /test/string?a=1&b=2http/1.1\r\n

So if we use a ngx_str_t struct to store this value, now we want to get the request type, is it get or post or put? We don't need to make a copy of the memory, we have to do just a new ngx_str_t, the data pointer is pointing to the original ngx_str_t an address, and then change Len to 3.
Of course, this is just one of the simplest applications, the string type is almost a variety of business systems, network framework is a very broad use of a basic type, good design structure is nginx low memory consumption of the important guarantee.

Operation of the ngx_str_t

The simple structure of a string is not particularly convenient, and in modern high-level languages such as Java,python, which provide rich manipulation of string types, Nginx also provides a number of common functions for string manipulation, although some do not seem so easy to use. So let's take a look at these functions.

Go to bed, write tomorrow.

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    The above describes the NGINX data structure-integer and string, including the aspects of the content, I hope to be interested in PHP tutorial friends helpful.

  • 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.