struct sdshdr
{
//记录buf中已经使用的字节的数量
//等于SDS所保存的字符串的长度
int len;
//记录buf数组中未使用的字节的数量
int free;
//字节数组,用于保存字符串(二进制的数据,不仅仅是字符串)。
char buf[];
}
1. The difference between the C string SDS
-
O (1) complexity Get string length
-
To prevent buffer overflow
-
The number of memory reallocation when reducing the modified string brings
3.1 pre-allocated space3.2 inert space freed
-
Binary security
by len field instead of '\ 0' is determined not to end. In this case, not only can save text, binary data can also be saved -
Compatible part c string functions
section <string.h> library functions can be used