Beispiel #1
0
 private void button1_Click(object sender, EventArgs e)
 {
     for (int i = 0; i < 1000000; i++)
     {
         //var buffer = new byte[TestData.Metadata.Length];
         //Array.Copy(TestData.Metadata, buffer, TestData.Metadata.Length);
         CIztUdpHeader header   = CIztUdpHeader.Load(TestData.Header, 0);
         CIztMetadata  metadata = CIztMetadata.Load(TestData.Header, 64);
         CIztPacket    packet   = CIztPacket.Load(TestData.Header, 0);
     }
 }
Beispiel #2
0
        public static CIztMetadata Load(byte[] buffer, int offset)
        {
            CIztMetadata metadata;

            if (buffer != null && (offset + LayoutSize) <= buffer.Length)
            {
                byte[] copydata = new byte[LayoutSize];
                Array.Copy(buffer, offset, copydata, 0, LayoutSize);

                //GCHandleType.Pinned 允許這個buffer做出來的handle直接取用底下的實體記憶體位置
                //相當於允許直接使用底層的C指標
                GCHandle handle = GCHandle.Alloc(copydata, GCHandleType.Pinned);
                metadata = (CIztMetadata)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(CIztMetadata));
                handle.Free();
            }
            else
            {
                metadata = new CIztMetadata();
            }

            return(metadata);
        }