redis_3.0.7_sds.c_sdscatlen()

源程序

sds sdscatlen(sds s, const void *t, size_t len)
{
	struct sdshdr *sh;
	size_t curlen = sdslen(s);

	s = sdsMakeRoomFor(s, len);//字符串添加len个长度
	if (s == NULL) return NULL;
	sh = (void*)(s - (sizeof(struct sdshdr)));
	memcpy(s + curlen, t, len);/*
								将指针t指向的字符串指向
								s+curlen的位置,长度为len
							   */
	sh->len = curlen + len;
	sh->free = sh->free - len;
	s[curlen + len] = '\0';
	return s;
}

说明

Append the specified binary-safe string pointed by 't' of 'len' bytes to the end of the specified sds string 's'. 源程序中的注释说明这里增长的字符串是二进制安全的。可是我并无看出来,之后再说,可能慢慢就懂了。安全

该函数的功能就是在原sds字符串的基础上添加len长度的字符串。新添加的字符串的头指针是t,添加到s的位置。curl

相关文章
相关标签/搜索
本站公众号
   欢迎关注本站公众号,获取更多信息