1号到3号休息,一个人在家。闲着也是闲着,准备完成一个网络协议的解析工作。 初步想用c++来实现,因为我想加入一些其它的c++的开源库进来。  如果时间够的话,再用Python来,权当练习编程语言吧。谨记之!

posted @ 2012-01-01 00:03 Repository 阅读(33) 评论(0) 编辑

2011年对我来讲是非常重要的一年,无论是从生活还是技术。

1.  技术总结:今年是我从工作以来接触新技术最多的一年。

   1.1 web前端:asp.net ,wpf, silverlight,当然还有公司自己的前端脚本语言。

   1.2 服务器端技术:nigix,memcache, redis, IOCP,ORM技术。

   1.3 架构方面:表现层MVC,WPF的MVVM。

   1.4 数据库:Mysql,sqlserver,sql server compact,sqlite。

   1.5 语言:c#,c,c++,python。

   1.6 行业: 2011年是Microsoft倒霉的一年,这和Microsoft的发展战略有关系。Microsoft向来都是什么行业都想插入一脚,一个人本人才两只脚,脚多了,都搞不清身体的重心该放在哪支脚上。Microsoft向来都是起得早,赶晚集,很多年前Microsoft就在移动领域有所占树,当前的windows ce,windowd mobile是何等的风光,现在有google,apple两大巨头,Microsoft现在又想重操旧业,重振雄风,目前希望不大,即使与NOKIA的合作,mango以及WP的推出,目前这几年想要从android与IOS嘴中抢食是很难的。再比如说Microsoft推出silverlight与adobe flash来抢食,结果如何,几乎遍体鳞伤,Microsoft打心底明白,silverlight想要web端占有一席之地,几乎不可能,于是Microsoft又转移战略目标,把silverlight转移到WP的开发,windows与Office目前是Microsoft主要的收入,Microsoft需要把精力专注在这两大块上面。可往往事与愿违,Microsoft技术路线非常广,不够专注,喜欢搞grammar sugar, 经常会有一种新技术来帮我们做来节省劳动力,提高效率,最后导致框架版本更新越来越频繁,IDE越来越大,MSDN文档越来越多,我想这是很我程序员抱怨Microsoft 的主要原因吧! 其实程序员只需要简单就可以。

 

2. 生活总结:已练就一身好厨艺,如果哪天我突然不想写代码了,可以往这方面发展一下。

3. 爱情总结:终于彻底告别以前分居二地工作的时间,可是我们家那位家伙工作太忙太拼命,以至于我们之间缺少一些心灵之间沟通与碰撞。

4 其它方面:看了不少的书,但没一本看完的。研究过P2P,IM,XNA,Mozilla extension技术。

 

这一年我做得不足的地方:

  技术:技术口味很杂,不够专注,可能跟工作内容有关。以来需要注意一下。

  生活:不够多姿多彩。

  爱情:有点大男子主义,缺少包容与体谅。

 

2012年展望:

   技术:转向开源平台,多研究一些开源的产品。关注移动互联网应用。

   爱情:希望我们小俩口爱情甜蜜。

   生活:要更丰富一些,多些锻炼,不能经常吃同一种菜。

 

新年愿望:

  愿我爸妈还有老丈人,丈母身体倍棒,吃嘛嘛香!

  愿哥哥与嫂子事业有成,财源滚滚!

  愿我那两个可爱的小侄女聪明伶俐!

  愿我们小俩口爱情事业双丰收,其实我希望那个家伙胖一点点!

  oh,my god, 这么多愿望,不念心吧!

 

  最后,

 

  愿我高中的班主任老师能战胜病魔!

  愿小利子的外婆能在天堂安息!请保佑我们吧!

  愿我认识的与不认识的朋友都幸福平安!

posted @ 2011-12-31 23:58 Repository 阅读(54) 评论(0) 编辑

  如果不想使用.net的webparts里的向导控件,可以自己设计一个简单的。我设计一个简单的向导框架,思路是这样的:

1. 首先会有一个向导类,我把它叫Navigation, 向导类有一个容器,里面包括本次向导中所有窗体。向导提供了向导框架中所有核心功能,比如:start, next step,previous step, finish。

2. 设计一个窗体基类,暂且叫BaseForm.所有向导窗体都继承这个基类,基类必须预留一些钩子(在C#语言中可以设计为virtual或者abstract,c++可为virtual),让各个派生的子类窗体去执行具体的窗体逻辑。比如:需要更新窗体title,处理业务逻辑等操作,另外,该窗口包含了一些向导控件(Next ,Previou,Finish,Cancel)。最后,必须把Navigation与窗体基类做关联。

3. 把所有向导窗体继续自BaseForm,并实现基类的钩子方法。

 

下面是用C#写的主要框架代码:

public class Navigation
{
    public List<BaseForm> container;
    public int currentIndex;

    public void Start() {currentIndex = 0; container[currentIndex].Show();}
    public void Finish() {currentIndex = container.Count-1;}
    public void Next();
    public void Previous();

     public Navigation()
     {
            currentIndex = 0;
            container  = new List<BaseForm>();
      }

     public void InitNavContainer()
     { 
            // TODO: Add your wizard forms step by step
            container.Add(.....)
     }

    public int IsHeadForm()
    {
          return (currentIndex == 0);
    }
     
    public int IsTailForm()
    {
          return (currentIndex == container.Count - 1);
    }
}

 

下面是窗体基类:

   1:  public class BaseForm : Form
   2:  {
   3:        public abstract void DoSomething();
   4:        public Button btnNext;
   5:        public Button btnPrevious;
   6:        public Button btnFinish;
   7:        public Button btnCancel;
   8:   
   9:        public Navigation navigation;
  10:   
  11:       public BaseForm(Navigation _navigation)
  12:      {
  13:            navigation = _navigation;
  14:       }
  15:   
  16:      public void OnNext()
  17:     {
  18:            navigation.Next();
  19:     }
  20:   
  21:     ........
  22:  }

  

子窗体代码很简单,所以代码都是直接写的,没有经过编译器compile过。 c# sucks.

posted @ 2011-11-25 23:22 Repository 阅读(19) 评论(0) 编辑
最后,内存分配直接用realloc来实现,该函数签名如下:
void *realloc( void *memblock, size_t size );

 

对于释放内存则直接利用memmove函数来实现
Moves one buffer to another.
void *memmove( void *dest, const void *src, size_t count );

 

下段摘自MSDN

 

Return Value
Moves one buffer to another.
void *memmove( void *dest, const void *src, size_t count );
Return Value
memmove returns the value of dest.
Parameters
dest
Destination object
src
Source object
count
Number of bytes of characters to copy
Remarks
The memmove function copies count bytes of characters from src to dest. If some regions of the source area and the destination overlap, memmove ensures that the original source bytes in the overlapping region are copied before being overwritten.
 

realloc returns a void pointer to the reallocated (and possibly moved) memory block. The return value is NULL if the size is zero and the buffer argument is not NULL, or if there is not enough available memory to expand the block to the given size. In the first case, the original block is freed. In the second, the original block is unchanged. The return value points to a storage space that is guaranteed to be suitably aligned for storage of any type of object. To get a pointer to a type other than void, use a type cast on the return value.

Parameters

memblock

Pointer to previously allocated memory block

size

New size in bytes

Remarks

The realloc function changes the size of an allocated memory block. The memblock argument points to the beginning of the memory block. If memblock is NULL, realloc behaves the same way as malloc and allocates a new block of size bytes. If memblock is not NULL, it should be a pointer returned by a previous call to calloc, malloc, or realloc.

The size argument gives the new size of the block, in bytes. The contents of the block are unchanged up to the shorter of the new and old sizes, although the new block can be in a different location. Because the new block can be in a new memory location, the pointer returned by realloc is not guaranteed to be the pointer passed through the memblock argument.

realloc calls malloc in order to use the C++ _set_new_mode function to set the new handler mode. The new handler mode indicates whether, on failure, malloc is to call the new handler routine as set by _set_new_handler. By default, malloc does not call the new handler routine on failure to allocate memory. You can override this default behavior so that, when realloc fails to allocate memory, malloc calls the new handler routine in the same way that the new operator does when it fails for the same reason. To override the default, call

_set_new_mode(1)

early in your program, or link with NEWMODE.OBJ.

When the application is linked with a debug version of the C run-time libraries, realloc resolves to _realloc_dbg. For more information about how the heap is managed during the debugging process, see Using C Run-Time Library Debugging Support.

 

有一点要注意,对于memblock为NULL的情况,该函数的作用与malloc一样,下面为sample:

 

  1:      long *pBuffer;
   2:      long size;
   3:      pBuffer = (long *)malloc(2*sizeof(long));
   4:      *pBuffer = 1;
   5:      *(pBuffer+1)=2;
   6:   
   7:      long l1 = *(pBuffer+1);
   8:      size = _msize(pBuffer);
   9:      cout << "size:" << size << "\t" << (*pBuffer) << "\t" << l1 << endl;
  10:   
  11:      //realloc
  12:      realloc(pBuffer,3*sizeof(long));
  13:      *(pBuffer+2)=6;
  14:      l1 = *(pBuffer+1);
  15:      long l2 = *(pBuffer+2);
  16:      size = _msize(pBuffer);
  17:      cout << "size:" << size << "\t" << (*pBuffer) << "\t" << l1 << "\t" << l2 << endl;
  18:      memmove(pBuffer+1,pBuffer+2,sizeof(long));
  19:      
  20:      size = _msize(pBuffer);
  21:      l1 = *(pBuffer+1);
  22:      //l2 = *(pBuffer+2);
  23:      cout << "size:" << size << "\t" << (*pBuffer) <<  "\t" << l1 << "\t" << l2 << endl;
posted @ 2011-11-13 14:56 Repository 阅读(19) 评论(0) 编辑

Here is the senario in my requirements:

  I need store datetime value in a serialization file(binary file). the file will be transfer to server side by network. the server-side is used c plus plus and it is responsible for parse the file tranfer from network. the file content contains different type data. of course,datetime value just be contained. Unfortunally, I write data to file use .net.

    How to store datetime value without use string format like this yyyy-MM-dd HH:mm:ss?

I got an idea, windows use 64-bit value to present datetime format value. I also can convert datetime to 64-bit value.

Let me to this:

   1:  private static DateTime origin = System.TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1, 0, 0, 0));
   2:   
   3:   public static System.DateTime Convert(UInt64 t)
   4:   {
   5:        DateTime convertedValue = origin + new TimeSpan((long)t * TimeSpan.TicksPerDay);
   6:        if (System.TimeZone.CurrentTimeZone.IsDaylightSavingTime(convertedValue) == true)
   7:        {
   8:            System.Globalization.DaylightTime daylightTime = System.TimeZone.CurrentTimeZone.GetDaylightChanges(convertedValue.Year);
   9:            convertedValue = convertedValue + daylightTime.Delta;
  10:        }
  11:        return convertedValue;
  12:    }
  13:   public static UInt64 ConvertBack(System.DateTime value)
  14:   {
  15:        DateTime convertedValue = value;
  16:        if (System.TimeZone.CurrentTimeZone.IsDaylightSavingTime(convertedValue) == true)
  17:        {
  18:            System.Globalization.DaylightTime daylightTime = System.TimeZone.CurrentTimeZone.GetDaylightChanges(convertedValue.Year);
  19:            convertedValue = convertedValue - daylightTime.Delta;
  20:       }
  21:       long diff = convertedValue.Ticks - origin.Ticks;
  22:       return (UInt64)(diff / TimeSpan.TicksPerDay);
  23:    }

 

I store total seconds in file. and I will parse the datetime easily in the server side .

the following is the c plus plus code:

   1:  struct tm gettime (long value)
   2:  {
   3:      time_t time = time_t(vlaue); 
   4:      struct tm t;
   5:      localtime_s (&t, &time);
   6:      //struct tm *tm2 = localtime(&ltime);
   7:      t.tm_year += 1900; 
   8:      t.tm_mon += 1;
   9:   
  10:      return t;
  11:  }

 

Great,you only need use localtime() function to do this. Is it so easy?

time_t is defined as a 64-bit int number type. in crtdefs.h header file, you will find this:

   1:  typedef __int64 __time64_t;     /* 64-bit time value */
   2:  typedef __time64_t time_t;      /* time value */

 

tm as struct defined in wchar.c

   1:  struct tm {
   2:          int tm_sec;     /* seconds after the minute - [0,59] */
   3:          int tm_min;     /* minutes after the hour - [0,59] */
   4:          int tm_hour;    /* hours since midnight - [0,23] */
   5:          int tm_mday;    /* day of the month - [1,31] */
   6:          int tm_mon;     /* months since January - [0,11] */
   7:          int tm_year;    /* years since 1900 */
   8:          int tm_wday;    /* days since Sunday - [0,6] */
   9:          int tm_yday;    /* days since January 1 - [0,365] */
  10:          int tm_isdst;   /* daylight savings time flag */
  11:          };

 

ok, util now. I solve the interoperation problem. It seems very easy.um…

posted @ 2011-11-01 16:26 Repository 阅读(71) 评论(0) 编辑
摘要: step: 1.初始化Winsock 2.创建一个完成端口 3.根据服务器线程数创建一定量的线程数 4.准备好一个socket进行bind然后listen 5.进入循环accept等待客户请求 6.创建一个数据结构容纳socket和其他相关信息 7.将连进来的socket同完成端口相关联 8.投递一个准备接受...阅读全文
posted @ 2011-09-30 15:06 Repository 阅读(54) 评论(0) 编辑
摘要: 通常断点续传指在都是应用在网络文件传输中,由于网络中断或其它原因导致文件需要重新传输,这时候只需要从最后中断前已读取的文件内容开始续传即可。我在这里省去了网络这一环节,全是本地操作。 断点续传原理非常简单:在传输过程中,每次写入内容至目标文件时,都需要记录一下文件流的offset即可。当下次程序重新启动后,读取这个offset值,再从offset的地方继续transfer。 这里我用c#简单写...阅读全文
posted @ 2011-08-17 16:15 Repository 阅读(149) 评论(0) 编辑
摘要: 局域网上的资源需要管理,“域”和“工作组”就是两种不同的网络资源管理模式。那么二者有何区别呢? 工作组 Work Group 在一个网络内,可能有成百上千台电脑,如果这些电脑不进行分组,都列在“网上邻居”内,可想而知会有多么乱。为了解决这一问题,Windows 9x/NT/2000就引用了“工作组”这个概念,将不同的电脑一般按功能分别列入不同的组中,如财务部的电脑都列入“财务部”工作组中,人事部的电脑都列入“人事部”工作组中。你要访问某个部门的资源,就在“网上邻居”里找到那个部门的工作组名,双击就可以看到那个部门的电脑了。 那么怎么加入工作组呢?其实很简单,你只需要右击你的Windows桌面上阅读全文
posted @ 2011-07-06 13:26 Repository 阅读(437) 评论(0) 编辑
摘要: 1. 准备工作:程序:MinGW-3.1.0-1.exe windows下的gcc,编译c语言的工具下载地址: http://umn.dl.sourceforge.net/sourceforge/mingw/MinGW-3.1.0-1.exemake 按照makefile规则编译程序的工具位置 :window/system32下,如果没有可以在 http://www.mingw.org/download.shtml找到配置环境: 环境变量配置 :控制面板> 系 统 >高级 >环境变量 >系统变量 >添加MinGW 安装目录下的bin目录到path中去,或者命令行下阅读全文
posted @ 2011-05-18 22:47 Repository 阅读(1686) 评论(0) 编辑
摘要: awk用法:awk'pattern{action}'变量名 含义ARGC 命令行变元个数ARGV 命令行变元数组FILENAME 当前输入文件名FNR 当前文件中的记录号FS 输入域分隔符,默认为一个空格RS 输入记录分隔符NF 当前记录里域个数NR 到目前为止记录数OFS 输出域分隔符ORS 输出记录分隔符1、awk'/101/'file显示文件file中包含101的匹配行。awk'/101/,/105/'fileawk'$1==5'fileawk'$1=="CT"'file注意必须带双引号a阅读全文
posted @ 2011-05-13 23:01 Repository 阅读(7984) 评论(0) 编辑