zoukankan      html  css  js  c++  java
  • Redis自定义动态字符串(sds)模块(二)

    sds模块的具体实现:

    1、sdsnewlen 根据参数生成一个sds字符串

     1 sds sdsnewlen(const void *init, size_t initlen) 
     2 {
     3     struct sdshdr *sh;
     4   //如果初始化的内容为NULL,则生成一个内容只有一个的串,但是长度不会变,还是传入的长度。zmalloc和zcalloc的功能一样,这个地方为啥还要调用不同的呢。
     5     if (init) {
     6         sh = zmalloc(sizeof(struct sdshdr)+initlen+1);
     7     } else {
     8         sh = zcalloc(sizeof(struct sdshdr)+initlen+1);
     9     }
    10     if (sh == NULL) return NULL;//申请失败返回NULL
    11     sh->len = initlen;//初始化长度为传入值。
    12     sh->free = 0;//设定剩余长度为0
    13     if (initlen && init)
    14         memcpy(sh->buf, init, initlen);//初始化值
    15     sh->buf[initlen] = '';填写最后的结尾符
    16     return (char*)sh->buf;
    17 }

    未完待续。。。

  • 相关阅读:
    C#面向对象
    C#语句
    C#语言数据类型
    Jupyter Notebook(iPython)
    BeautifulSoup模块
    requests模块
    爬虫基本原理
    版本控制系统
    支付宝支付
    django内置组件——ContentTypes
  • 原文地址:https://www.cnblogs.com/likui360/p/5274041.html
Copyright © 2011-2022 走看看