Simple dynamic string of Redis

struct sdshdr
{
	//记录buf中已经使用的字节的数量
	//等于SDS所保存的字符串的长度
	int len;
	//记录buf数组中未使用的字节的数量
	int free;
	//字节数组,用于保存字符串(二进制的数据,不仅仅是字符串)。
	char buf[];
}

1. The difference between the C string SDS

  1. O (1) complexity Get string length

  2. To prevent buffer overflow

  3. The number of memory reallocation when reducing the modified string brings
    3.1 pre-allocated space

    3.2 inert space freed

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

  5. Compatible part c string functions
    section <string.h> library functions can be used

Published 306 original articles · won praise 46 · views 290 000 +

Guess you like

Origin blog.csdn.net/kaikai_sk/article/details/89553745