keep_simple

导航

随笔分类 -  C++

c++编程学习
关于C++11中的std::move和std::forward
摘要:std::move是一个用于提示优化的函数,过去的c++98中,由于无法将作为右值的临时变量从左值当中区别出来,所以程序运行时有大量临时变量白白的创建后又立刻销毁,其中又尤其是返回字符串std::string的函数存在最大的浪费。比如:1 std::string fileContent = “oldContent”;2 s = readFileContent(fileName);因为并不是所有情况下,C++编译器都能进行返回值优化,所以,向上面的例子中,往往会创建多个字符串。readFileContent如果没有内 部状态,那么,它的返回值多半是std::string(const std::s 阅读全文

posted @ 2013-08-10 16:34 keep_simple 阅读(1780) 评论(0) 推荐(0)

内存池管理
摘要:http://www.codeproject.com/Articles/15527/C-Memory-Pool 阅读全文

posted @ 2013-05-10 15:04 keep_simple 阅读(225) 评论(0) 推荐(0)

简易tcp服务器
摘要:server:View Code 1 #include <stdlib.h> 2 #include <string.h> 3 #include <iostream> 4 #include <sys/socket.h> 5 #include <sys/epoll.h> 6 #include <netinet/in.h> 7 #include <arpa/inet.h> 8 #include <fcntl.h> 9 #include <unistd.h> 10 #include <st 阅读全文

posted @ 2013-04-28 14:42 keep_simple 阅读(331) 评论(0) 推荐(0)

设置线程属性
摘要:1 #include <pthread.h> 2 #include <unistd.h> 3 #include <cstdio> 4 #include <cstdlib> 5 #include <iostream> 6 7 void* threadRun(void * arg) 8 { 9 sleep(1);10 11 return 0;12 }13 14 int main()15 {16 char szLog[256] = {0};17 int const threadNum_ = 10;18 pthread_t * writeTh 阅读全文

posted @ 2013-01-11 10:04 keep_simple 阅读(353) 评论(0) 推荐(0)

简单框架
摘要:1 #include <iostream> 2 #include <vector> 3 #include <algorithm> 4 using namespace std; 5 class Base 6 { 7 public: 8 9 virtual void run()=0; 10 11 }; 12 13 template<class T> 14 class BaseT: public Base 15 { 16 public: 17 static Base* get() 18 { 19 return new T; 20 ... 阅读全文

posted @ 2012-12-24 15:08 keep_simple 阅读(288) 评论(0) 推荐(0)