Redis custom Dynamic String (SDS) module (ii)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.