Internal Data Structures

There are some data structures that are important and widely used in the server. We will describe them in detail in this section.

Note

There are many more structures and types defined across the server and modules. We will describe only the most important and common data structure here. The rest will be described in other sections if needed.

Type str

One of our main goals was to make SER really fast. There are many functions across the server that need to work with strings. Usually these functions need to know string length. We wanted to avoid using of strlen becase the function is relatively slow. It must scan the whole string and find the first occurence of zero character. To avoid this, we created str type. The type has 2 fields, field s is pointer to the beginning of the string and field len is length of the string. We then calculate length of the string only once and later reuse saved value.

Important

str structure is quite important because it is widely used in SER (most functions accept str instead of char*).

str Type Declaration

struct _str{
    char* s;
    int len;
};

typedef struct _str str;		    

The declaration can be found in header file str.h.

Warning

Because we store string lengths, there is no need to zero terminate them. Some strings in the server are still zero terminated, some are not. Be carefull when using functions like snprintf that rely on the ending zero. You can print variable of type str this way:

printf("%.*s", mystring->len, mystring->s);
That ensures that the string will be printed correctly even if there is no zero character at the end.