The specific implementation of SDS modules:
1. Sdsnewlen generates an SDS string according to the parameters
1SDS Sdsnewlen (Const void*init, size_t Initlen)2 {3 structSDSHDR *sh;4If the contents of the initialization are null, a string with only one of the contents is generated, but the length does not change, or the length passed in. Zmalloc and Zcalloc function like, why is this place to call different?5 if(init) {6SH = zmalloc (sizeof(structSDSHDR) +initlen+1);7}Else {8SH = zcalloc (sizeof(structSDSHDR) +initlen+1);9 }Ten if(sh = = NULL)returnnull;//request failed return NULL OneSh->len =initlen;//initialization length is the value passed in. ASh-> Free=0;//Set the remaining length to 0 - if(Initlen &&init) -memcpy (sh->buf, Init, initlen);//Initialize value theSh->buf[initlen] =' /'; Fill in the last end of the letter - return(Char*) sh->buf; -}
Not to be continued ...
Redis custom Dynamic String (SDS) module (ii)