• 2007-10-11

    Congratulations..milestone

    版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
    http://rockliao.blogbus.com/logs/10240925.html

    Why I update my blog at this special time? That's because I just finished a very important work which can be called as a milestone. Although there was much unhappiness yestoday night, my temper is much better now. I find that working is one of the best regulator for the bad temper. What's the others ? Ask yourself...

    OK, in this chapter, let's go over the "data structure". I happened to find a very good use of "ring buffer" in our code, so just take out to share with you.

    First, ring buffer is used to cache the data and can be reused. Second, ring buffer can not be loaded completely full, it must leave one node as a symbol of full. Very foundational..

    In our code, we use a malloc ring buffer between two tasks to help the data transfer. We use the mssage queue to send the "pointer" which point to the buffer address and the receiver can just use the pointer to read the data from the ring buffer.That's very efficient !

    However,I have to list the code of the ring buffer:

    int InitRingQueue(SqQueue_t *Q)
    {
     Q->base = (QElemType *)malloc(sizeof(QElemType) * MAXRINGQSIZE);
     if(!Q->base)
     {
      printf("malloc failed\r\n");
     }
     Q->next = Q->prior = 0;
     return 0;

    int WriteRingQueue(SqQueue_t *Q,QElemType e)
    {
     if((Q->prior +1)%MAXRINGQSIZE == Q->next)
     {
      //printf("out of queue: %d\r\n",Q.prior);
      return -1;
     }
     Q->base[Q->prior] = e; 
     Q->prior = (Q->prior + 1) % MAXRINGQSIZE;
     return 0;

    int ReadRingQueue(SqQueue_t *Q,QElemType **e)
    {
     if(Q->next == Q->prior)
     {
      /*printf("write is equal to read\r\n");*/
      return -1;
     }
     *e = &Q->base[Q->next];
     Q->next = (Q->next + 1) % MAXRINGQSIZE;
     return 0;


    随机文章:

    离别杭州 2008-04-06
    两种愉悦 2007-11-15
    system crash 2007-11-07
    涂鸦 2007-10-27
    Dota的艺术 2007-10-13

    收藏到:Del.icio.us




    评论

  • Hypocritical!! Dont you have a notebook!? That\'s a better way to organize knowledge I guess!!
  • 好歹我也要记录下研发的心得撒。。不然太水了。。那你就只看第一段嘛,后面的不用看了。。。
  • I agree with Song Tao. Please, share more stuff about life we common people can understand, like the first section of this article, rather than the programming skills.....
  • 多思考
  • 在可以预见的未来就能看见了,我上个月和女朋友注册了。不过婚礼还要等明年。
  • 嘿嘿...你什么时候弄个小宋涛来瞧瞧..
  • 廖猫,几年不见,你现在老出息了。好好干哈。现在每天都关注你的BLOG,别只写编程的体会,现在我基本上看不懂代码了。多写些你生活点滴。想你。
  • 恩?哦。。
  • 我看不懂英文,TKS
  • 果然是记录研发的点点滴滴~~~
  • 不要把情绪放大嘛~~没那么严重~~放松~~