Пример #1
0
        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);
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="start"></param>
        /// <param name="len"></param>
        /// <returns></returns>
        public override MarshalMemoryBlock Read(long start, int len)
        {
            var vtmp = len / 1024 * 100;

            vtmp = len % (1024 * 100) > 0 ? vtmp + 1 : vtmp;

            MarshalMemoryBlock re = new MarshalMemoryBlock(len, 1024 * 100);

            mStream.Position = start;

            byte[] bval = new byte[len];
            mStream.Read(bval, 0, len);
            re.WriteBytesDirect(0, bval);

            //mStream.Write(re.StartMemory, 0, len);
            return(re);
        }