- 博客(13)
- 资源 (9)
- 收藏
- 关注
原创 Redis源代码分析之七:事件驱动库分析——Ae
aeEventLoop是一个记录记录程序事件状态的结构:/* State of an event based program */ typedef struct aeEventLoop { int maxfd; long long timeEventNextId; aeFileEvent events[AE_SETSIZE]; /* Registered events */
2012-02-27 15:12:49 5278 1
原创 Redis源代码分析之六:Redis执行流程
现在我们分析Redis从启动开始的执行流程,从而顺藤摸瓜地理解其事件驱动模型。 首先找到main入口: int main(int argc, char **argv) { time_t start; initServerConfig(); if (argc == 2) { if (strcmp(argv[1], "-v") == 0 ||
2012-02-27 14:09:40 8651
原创 由二叉树的前序遍历序列和中序遍历序列求后序遍历序列
给出二叉树的前序遍历序列和中序遍历序列,求后序遍历序列。比如节点内存储的数据类型为char的二叉树,给出前序遍历序列"abdec",中序遍历序列"dbeac",则输出后序遍历序列。 可以写一个递归函数实现,首先由前序遍历序列的第一个元素确定根节点,然后再中序遍历序列中找出等于该元素的位置索引,则根据中序遍历的定义,该位置以左为左子树,以右为右子树。根据前序遍历的定义,第一个元素之后跟着的也分别是
2012-02-24 10:04:27 10360
原创 TCP/IP笔记二:IP头部/UDP/TCP校验和的计算
The IP checksum is the 16 bit one's complement of the one's complement sum of all 16 bit words in the header. “1的补码”即反码。 IP只对首部而不对数据部分计算校验和,计算方法是将首部视为16位整数的序列,对首部所有16位整数各求反码,并将结果相加,再对求得的和计算一次二进制反码
2012-02-19 20:12:40 2174
原创 TCP/IP笔记一:判断子网类型的几个宏
最近在看《用TCP/IP进行网际互联》和《TCP/IP详解》,以及TCP/IP的几个开源实现:Xinu实现、BSD实现、lwIP实现、uIP实现,做一些小的笔记。、 下面是Xinu中判断子网类型的几个宏: #if BYTE_ORDER == BIG_ENDIAN #define IP_CLASSA(x) (((x) & 0x80000000) == 0) /* IP Class A */ #
2012-02-16 13:30:04 1495
转载 Rails错误:LoadError: no such file to load – openssl 解决办法
Install openssl and openssl-devel. aptitude install libssl-dev Go to your Ruby source directory and run the following commands: cd ext/openssl rvmsudo ruby extconf.rb make make install
2012-02-10 11:11:58 2005
原创 Redis源代码分析之五:简单动态字符串——Sds
一个Redis字符串的结构体定义是: struct sdshdr { int len; int free; char buf[]; }; 其中buf字符数组中储存实际的字符串。len变量保存字符串的长度。free变量指出还有多少字节可用。 sds被定义为一种新的数据类型,实际就是字符指针: typedef char *sds; 例如,sdsnewlen
2012-02-04 15:40:27 2338
转载 【Redis】Why is an Event Library needed at all?
Let us figure it out through a series of Q&As. Q: What do you expect a network server to be doing all the time? A: Watch for inbound connections on the port its listening and accept them. Q: C
2012-02-04 15:05:34 1410
原创 Redis源代码分析之四:Unix底层网络通信——Anet
还是先介绍接口: int anetTcpConnect(char *err, char *addr, int port); int anetTcpNonBlockConnect(char *err, char *addr, int port); int anetUnixConnect(char *err, char *path); int anetUnixNonBlockConnect(ch
2012-02-04 14:29:33 4399 1
原创 Redis源代码分析之三:散列表——Dict(下)
下面分析散列表常见操作,如插入、删除、替换等。 散列表插入函数dictAdd实现如下: /* Add an element to the target hash table */ int dictAdd(dict *d, void *key, void *val) { int index; dictEntry *entry; dictht *ht; if
2012-02-04 11:48:44 3068
原创 Redis源代码分析之二:散列表——Dict(上)
先介绍Redis散列表实现的几个重要数据结构: 字典项DictEntry: typedef struct dictEntry { void *key; void *val; struct dictEntry *next; } dictEntry; 字典类型DictType: typedef struct dictType { unsigned
2012-02-01 20:16:48 3952
原创 Redis源代码分析之一:内存管理——Zmalloc
首先Zmalloc的接口定义在头文件Zmalloc.h里: void *zmalloc(size_t size); void *zcalloc(size_t size); void *zrealloc(void *ptr, size_t size); void zfree(void *ptr); char *zstrdup(const char *s); size_t zmalloc_use
2012-02-01 19:05:05 8612 1
转载 The architecture of REDIS
REDIS is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets. Redis works with an in-memo
2012-02-01 16:33:53 2049
The Architecture of Open Source Applications
2011-09-17
C++标准库,Boost简介
2007-05-20
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人