[收藏]IOCP Thread Pooling in C#[9]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 zhengyun_ustc 的 blog

next add the namespace.   you will notice that i have defined a two level namespace.  this is great when you are building a class library with many different classes.

 

namespace continuum.threading

{

 

the postqueuedcompletionstatus and getqueuedcompletionstats win32 api methods both require a pointer to the win32 overlapped structure.  because this structure will be used by the unsafe win32 api call, we need to make sure the structure is aligned exactly the same way it would be in our c++ applications.  this can be accomplished by using the structlayout attribute.  by setting the attribute to “layoutkind.sequential”, the structure will be aligned based on the same rules as the c++ compiler.

 

the structure requires members that are pointers.  the only way to add pointers to this structure is to use the unsafe keyword.  we can still use the fcl types when defining the structure.  this is very important because we can make sure the structure is identical to the c++ version.

 

// structures

 

  //=============================================================================

  /// <summary> this is the win32 overlapped structure </summary>

  [structlayout(layoutkind.sequential, charset=charset.auto)]

  public unsafe struct overlapped

  {

    uint32* ulpinternal;

    uint32* ulpinternalhigh;

    int32   loffset;

    int32   loffsethigh;

    uint32  hevent;

  }

 

本文关键:[收藏]IOCP Thread Pooling in C#
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top