网络服务器软件开发/中间件开发,关注ACE/ICE/boost

C++博客 首页 新随笔 联系 聚合 管理
  152 Posts :: 3 Stories :: 172 Comments :: 0 Trackbacks

#

这几天,陆续在网上见到了几个高中的好同学,发现曾经很优秀的他们,现在对游戏竟然都上瘾了,由于高中管理严格,所以没有机会出去玩,到了大学,
可谓是天时地利人和,控制不住自己,疯玩。工作混得一塌糊涂,却不忘游戏,可叹!再过上10年,人和人就会是天壤之别,希望他们早点清醒自己的头脑,别在沉浸在游戏中了,是该奋斗的时候了!

posted @ 2009-01-11 18:14 true 阅读(881) | 评论 (10)编辑 收藏

以后要努力做到这一点,也是提高开发速度的良方!
posted @ 2008-12-10 16:37 true 阅读(348) | 评论 (1)编辑 收藏

白天写代码效率比较低,晚上愿意写代码,看来就是熬夜的命
posted @ 2008-12-08 15:29 true 阅读(346) | 评论 (3)编辑 收藏

LNK2001 的一个原因如下,小知识不经常写容易忘记,昨天下午到现在一天时间没了
成员模板的定义超出了类的范围。Visual C++ 的一个限制是,成员模板的定义必须完全位于封闭类内
posted @ 2008-11-21 10:15 true 阅读(347) | 评论 (0)编辑 收藏

像下面的好用工具函数就无法使用:
string format_string(const char *fmt, ...)
{
 /* Guess we need no more than 512 bytes. */
 int n, size = 512;
 char *p;
 va_list ap;
 if ((p = (char*)malloc (size)) == NULL)
  return "";
 while (1)
 {
  /* Try to print in the allocated space. */
  va_start(ap, fmt);
  n = vsnprintf (p, size, fmt, ap);
  va_end(ap);
  /* If that worked, return the string. */
  if (n > -1 && n < size)
  {
   string str(p);
   if(p)
    free(p);
   return str;
  }
  /* Else try again with more space. */
  if (n > -1)    /* glibc 2.1 */
   size = n+1; /* precisely what is needed */
  else           /* glibc 2.0 */
   size *= 2;  /* twice the old size */
  if ((p = (char*)realloc (p, size)) == NULL)
  {
   if(p)
    free(p);
   return "";
  }
 }
}  

posted @ 2008-10-07 10:17 true 阅读(2310) | 评论 (2)编辑 收藏

      浮躁是比较可怕的,技术上处于平原期,没有什么提高,以后的路在何方?感慨万千
posted @ 2008-09-25 12:57 true 阅读(252) | 评论 (0)编辑 收藏

     message queue亦即消息队列,在linux 下有msgsnd,msgrcv系列,在windows下有msmq,关于他们的相似及区别,请查阅相关资料,本文主要是简单介绍一下boost提供的解决方案,及其性能。
   boost提供的message queue发送接口有send,try_send,timed_send,接收接口有receive,try_receive,timed_receive,其它接口有get_max_msg,get_max_msg_size,get_num_msg,remove。学习难度不高。下面测试一下send的发送速度:
    测试代码:

#define BOOST_ALL_DYN_LINK
#include <boost/interprocess/ipc/message_queue.hpp>
#include <boost/format.hpp>
#include <boost/progress.hpp>
#include <iostream>
#include <string>
#include <vector>

using namespace boost;
using namespace boost::interprocess;

#define MAX_MSG_COUNT 50000
#define MAX_MSG_SIZE 1024

int main ()
{
try{
  //Erase previous message queue
  message_queue::remove("message_queue");

  //Create a message_queue.
  message_queue mq
   (create_only               //only create
   ,"message_queue"           //name
   ,MAX_MSG_COUNT                       //max message number
   ,MAX_MSG_SIZE               //max message size
   );
  
  
  {
   progress_timer pt;//记录时间,多方便!
  
   for(int i = 0; i < 5000; ++i)//可灵活调整i的大小
   {    
    std::string msg = str(format("hello world %d") % i);
    bool bRet = mq.send(msg.c_str(),msg.size(),0);  
   }
  }
  
}

catch(interprocess_exception &ex)
{
  message_queue::remove("message_queue");
  std::cout << ex.what() << std::endl;
  return 1;
}
//message_queue::remove("message_queue");
return 0;
}

  我的测试结果如下:
500    0.16s
1000   0.41/0.50  -->表示测了2次,第一次0.41s,第二次0.50s,下同
5000条 5.88s/6.16
10000  22.81s/22.34
20000  87.92/91.22

   最后简单总结一下boost message queue:
  优点:速度还不错,接口学习起来简单,方便易用
  缺点:我在windows下测试,当一直在写队列时,用ctrl + c中断,然后用另一进程读读队列,读操作时阻塞。单步跟踪发现
  是阻塞在interprocess_mutex::lock加锁的操作上,健壮程度远不如msgsnd,msgrcv系列,及msmq,该缺点比较致命。目前没有测试linux下的情况。
posted @ 2008-07-31 08:58 true 阅读(7017) | 评论 (0)编辑 收藏

     摘要: ADSL大型技术专题(图文) 2007-5-23 8:24:59 随着ADSL的普及,宽带包月费用不断的下调,现在越来越多的家庭用户装上了ADSL宽带上网,申请了ADSL上网以后,该如何接入上网呢?需要什么设备?如果家里有多台电脑,又该如何接入,使得A...  阅读全文
posted @ 2008-07-30 11:27 true 阅读(6880) | 评论 (0)编辑 收藏

     摘要:         关于echo的简单server,几乎多得发指,但大部分都没有提供类似粘包,定时器,安全退出等开发中的常用机制,换句话说,为了echo而echo,借鉴价值大打折扣,毕竟我们平时的工作不可能这么简单。这几天研究了下asio,感觉不错,boost接纳asio后,在服务器开发领域是不是该得到重视呢:),还是贴代码吧,有注...  阅读全文
posted @ 2008-07-20 13:45 true 阅读(3662) | 评论 (3)编辑 收藏

#include <iostream>
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

int main()
{
 boost::asio::io_service io;

 boost::asio::deadline_timer t(io, boost::posix_time::seconds(5));
 t.wait();

 std::cout << "Hello, world!\n";

 return 0;
}

上面是boost文档自带的代码,编译出现错误。代码是不需要链接libboost_system-vc80-mt-gd-1_35.lib,为什么还出现这样的错误呢?他默认连接?知道的,恢复一下:)
posted @ 2008-07-16 13:19 true 阅读(11348) | 评论 (13)编辑 收藏

仅列出标题
共15页: First 3 4 5 6 7 8 9 10 11 Last