2014年2月10日

摘要: 因为项目需要,需要使用zookeeper。zookeeper就不用介绍了,具体见此文。http://www.ibm.com/developerworks/cn/opensource/os-cn-zookeeper/#icommentszookeeper有点类似epoll的ET模式,事件只会通知一次,当通知完只会,需要再次注册。不然不会通知了。注意:1)哪些函数监听哪些事件类型。比如:getChild函数如果节点不存在,不会记录这个watcher,而且不能监听set事件。当父节点被删除时,也会触发2)每个功能都有多个函数原型,为的就是能够在多个地方设置watcher回调。默认的回调函数都是在初始 阅读全文
posted @ 2014-02-10 15:29 51Liuda 阅读(1076) 评论(0) 推荐(0) 编辑

2014年1月14日

摘要: 时不时的被编码折腾一下>>> print urllib.quote('中国') %E4%B8%AD%E5%9B%BD>>> s = '%E4%B8%AD%E5%9B%BD'>>> print urllib.unquote(s).decode('utf8')中国>>> s=urllib.quote('中国').encode('utf8') >>> print s%E4%B8%AD%E5%9B%BD>>> s=u 阅读全文
posted @ 2014-01-14 21:57 51Liuda 阅读(315) 评论(0) 推荐(0) 编辑

2013年10月10日

摘要: This chapter describes the interfaces that providers use for communication with Apple Push Notification service (APNs) and discusses some of the functions that providers are expected to fulfill.General Provider RequirementsAs a provider you communicate with Apple Push Notification service over a bin 阅读全文
posted @ 2013-10-10 12:06 51Liuda 阅读(880) 评论(0) 推荐(0) 编辑
摘要: 1,最通用的模板交换函数模式:创建临时对象,调用对象的赋值操作符。[cpp]view plaincopyprint?templatevoidswap(T&a,T&b){Tc(a);a=b;b=c;}需要构建临时对象,一个拷贝构造,两次赋值操作。2,针对int型优化:[cpp]view plaincopyprint?voidswap(int&__restricta,int&__restrictb){a^=b;b^=a;a^=b;}无需构造临时对象,异或因为指针是int,所以基于这个思路可以优化1:[cpp]view plaincopyprint?templatev 阅读全文
posted @ 2013-10-10 11:15 51Liuda 阅读(32919) 评论(0) 推荐(1) 编辑

2013年8月20日

摘要: 1:定义string字符串,返回的是指针 例子: s := "hello"if s[1] != 'e' { os.Exit(1) }s = "good bye"var p *string = &s*p = "ciao"下面的语句就是非法的.s[0] = 'x'(*p)[1] = 'y'注意: 1:string返回的是指针,但是这个值不能被修改。就像const char*2:string... 阅读全文
posted @ 2013-08-20 16:50 51Liuda 阅读(221) 评论(0) 推荐(0) 编辑

2013年6月18日

摘要: int a=(int)(((int *)0x0)+4);这题其实很简单,但是我想错了。这样拆分吧首先这道题是计算什么,是计算地址。char *p = NULL;cout<<(int)p<<endl;上面的结果就是打印为0。指针p里面记录着指向的地址,值为0。如下,就是计算p1的地址int * p = 0;int *p1 = p+4;cout<<(int)p1<<endl;所以,p+4是偏移了4个字节。所以答案为16。 阅读全文
posted @ 2013-06-18 09:50 51Liuda 阅读(128) 评论(0) 推荐(0) 编辑

2013年5月29日

摘要: 之前断断续续的阅读过redis,memcache的源代码,没有深入。 一段时间不看,基本就忘记了。收效甚微。 接下去的一段时间,准备开始再次深入的阅读redis,memcache,nginx的源代码。 这次主要以给源代码写单元测试和注释结合的方式阅读,这样能更深入的去理解其设计精髓。 阅读全文
posted @ 2013-05-29 15:20 51Liuda 阅读(147) 评论(0) 推荐(0) 编辑

2013年5月21日

摘要: strace-T-c-p10700 阅读全文
posted @ 2013-05-21 08:52 51Liuda 阅读(87) 评论(0) 推荐(0) 编辑

2012年12月6日

摘要: 有限状态机#include<iostream>#include<vector>using namespace std;typedef struct Context{ int iNext;}Context_t;void processor(Context_t &context,vector<int>& requests,vector<int>& results){ switch(context.iNext){ case 1: { cout<<"11111111111111"<<en 阅读全文
posted @ 2012-12-06 10:04 51Liuda 阅读(244) 评论(0) 推荐(0) 编辑

2012年8月29日

摘要: 在linux上编译程序,确实是一个苦差事。平时一般用Cmake编译项目。cmake.&&make1)首先看下陈皓写的跟我一起写makefilehttp://wiki.ubuntu.org.cn/index.php?title=%E8%B7%9F%E6%88%91%E4%B8%80%E8%B5%B7%E5%86%99Makefile&variant=zh-cn2)补充一些a)生成.so和生成.a文件的办法#生成.a文件main:util.o ar rc libddd.a util.outil.o:util.h g++ -c util.cppclean: ... 阅读全文
posted @ 2012-08-29 19:31 51Liuda 阅读(2876) 评论(0) 推荐(0) 编辑

导航