public void TimeTest2() { MarshalMemoryBlock memory = new MarshalMemoryBlock((long)(1024 * 1024 * 1024) * 3); DateTime dt = DateTime.Now; long ltmp = (long)(1024 * 1024); memory.WriteByte(ltmp, (byte)20); memory.WriteDatetime(memory.Position, dt); memory.WriteDouble(memory.Position, 20.5); memory.WriteFloat(memory.Position, 20.5f); memory.WriteString(memory.Position, dt.ToString(), Encoding.Unicode); memory.WriteInt(memory.Position, 20); memory.WriteLong(memory.Position, 20); memory.WriteShort(memory.Position, (short)20); memory.WriteUShort(memory.Position, (ushort)20); memory.WriteUInt(memory.Position, 20); memory.WriteULong(memory.Position, 20); MarshalMemoryBlock mm = new MarshalMemoryBlock(1024); Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < 1000000; i++) { memory.WriteBytesDirect(500, memory.StartMemory + (int)ltmp, 0, 50); memory.WriteUShortDirect(550, 50); memory.WriteByte(550, 1); } sw.Stop(); Debug.Print("10000000:" + sw.ElapsedMilliseconds); }
/// <summary> /// /// </summary> /// <param name="id"></param> /// <returns></returns> public MarshalFixedMemoryBlock GetStatisticsData(int id) { MarshalFixedMemoryBlock re = null; if (id >= StartId && id < StartId + TagTotalCount) { var vid = mHead.ReadLong((id - StartId) * 8); if (vid == 0) { re = new MarshalFixedMemoryBlock((mData.Buffers[0] + mAvaiableDataLen), 48 * 24); mHead.WriteLong((id - StartId) * 8, mAvaiableDataLen); mAvaiableDataLen += 48 * 24; } else { re = new MarshalFixedMemoryBlock((mData.Buffers[0] + (int)vid), 48 * 24); } } return(re); }