struct C_Ctl
{
fixed byte Share[CHAN_DIRS]; // flags and ptrs to read & write memory
};

解决方案 »

  1.   

    [StructLayout(LayoutKind.Sequential,Pack=1)]
            unsafe struct Chan
            {
                IntPtr BuffEmpty; // Buffer is empty
                IntPtr BuffFull; // Buffer has data in it
                fixed byte data[MAX_PACKET]; // The data, 1st byte is len
            }        [StructLayout(LayoutKind.Sequential, Pack = 1)]
            unsafe struct C_Ctl
            {
                fixed byte Share[CHAN_DIRS * 263]; // flags and ptrs to read & write memory
                public Chan GetShareChan(int index)
                {
                    fixed (byte* p = Share)
                    {
                        return *(Chan*)(p + index*sizeof(Chan));
                    }
                }
            }
      

  2.   

    Chan *Share[CHAN_DIRS];代表一连串Chan结构的地址,简单可以转换为:
    Chan[] Share = new Share[CHAN_DIRS]应用地址时候可以采用:
    unsafe
    {
      Chan *pChan = &Share[i]; // i : 0 ~ CHAN_DIRS - 1
      pChan->BuffEmpty = ... 
    }