【发布时间】:2017-11-12 02:20:56
【问题描述】:
当我调试 Redis SkipList 时,我想使用 zslGetElementByRank(t_zset.c)。我把Redis的主要功能代码替换为:
int main(int argc, char **argv) {
zskiplistNode *node;
zskiplist *zsl = zslCreate(); //create a skiplist
zslInsert(zsl, 65.5, sdsnew("tom")); //insert some data
zslInsert(zsl, 87.5, sdsnew("jack"));
zslInsert(zsl, 70.0, sdsnew("alice"));
zslInsert(zsl, 95.0, sdsnew("tony"));
printf("The Rank equal 4 is :");
node = zslGetElementByRank(zsl, 4); //get element by rank
printf("%s->%f\n", node->ele, node->score);
return 0;
}
$ 制作
$ ./src/redis 服务器
[1] 29749 分段错误 ./src/redis-server // 我得到一个分段错误
然后,我调试代码,在 zslGetElementByRank 和 main 中打印地址,地址是:
(gdb) p x x is zslGetElementByRank returnd
$1 = (zskiplistNode *) 0x7ffff6e25000
(gdb) p 节点
$2 = (zskiplistNode *) 0xfffffffff6e25000
为什么地址从0x7ffff6e25000变成0xfffffffff6e25000,我很困惑。
不好意思忘记了,我的Redis版本是4.0.1
谢谢!
【问题讨论】:
-
我用 glibc malloc 重新编译代码: $ make MALLOC=libc $./src/redis-server 等级等于 4 是 :tony->95.000000 答案是正确的,但我没有原因。
标签: redis skip-lists