摘要:服务器代码依赖了boost的function和bind,用来做回调,异步调用时会出现这种down机.闲话少说上代码:void fn(std::string str);char *temp_str = new char[24];strcpy(temp_str,"1212");boost::function f = boost::bind(fn,temp_str);f();这边的f函数对象里面保存了一个temp_str的指针,如果是同步调用,会有临时的std::string变量产生,产生拷贝一次temp_str,之后就不在引用temp_str,所以不会出现任何问题;可是如果是异
阅读全文
摘要:如果你暴露一个复杂对象给Lua,实现类似于OO编程的话,那么也要把析构函数暴露给Lua.否则的话,lua gc的时候,回收垃圾对象,没有找到回收函数,就直接free掉了,这在C++中,是相当致命的.tolua++中的tolua_cclass函数,用来注册lua对象,TOLUA_API void tolua_cclass (lua_State* L, const char* lname, const char* name, const char* base, lua_CFunction col)同时会把最后的那个参数col,注册到lua对象的元表里面:static void push_colle
阅读全文
摘要:1, 下载compiler和源代码,或直接下bin包http://code.google.com/p/protobuf/downloads/build protobuf:C++代码./configuremakemakecheckmakeinstall2, 创建一个addressbook.protoC++代码packagetutorial;messagePerson{requiredstringname=1;requiredint32id=2;optionalstringemail=3;enumPhoneType{MOBILE=0;HOME=1;WORK=2;}messagePhoneNumbe
阅读全文