Exemple #1
0
        public static void MainTestLongStream()
        {
            MemoryStreamLongSize stream = new MemoryStreamLongSize(1, 4);

              // TestByOneByte(stream);

            TestByBuffer(stream);
        }
Exemple #2
0
 // Кешевое решение
 //System.IO.MemoryStream ms = null;
 //System.IO.BinaryReader mbr = null;
 // Формирование кеша
 public void ActivateCache()
 {
     Console.WriteLine("cell {0} activating...", ((System.IO.FileStream)this.fs).Name);
     fs.Position = 0;
     Console.WriteLine("q "+this.fs.Length);
     Console.WriteLine("w "+(int)this.fs.Length);
     var ms = new MemoryStreamLongSize((int)this.fs.Length);
     this.fs.CopyTo(ms);
     //MyMemoryReadStream ms = new MyMemoryReadStream(this.fs, this.fs.Length);
     this.fs = ms;
     this.br = new System.IO.BinaryReader(fs);
     //this.bw = new System.IO.BinaryWriter(fs);
     activated = true;
 }
Exemple #3
0
        private static void TestByOneByte(MemoryStreamLongSize stream)
        {
            stream.WriteByte(Convert.ToByte(2));
            stream.Seek(0, SeekOrigin.Begin);
            Console.WriteLine(stream.ReadByte());
            Console.WriteLine(stream.ReadByte());
            stream.Seek(0, SeekOrigin.Begin);
            for (int i = 0; i < 1000 * 1000 * 1000; i++)
            {
                stream.WriteByte(Convert.ToByte(i % 8));
            }
            stream.Seek(0, SeekOrigin.Begin);

            for (int i = 0; i < stream.Length; i++)
            {
                var readByte = stream.ReadByte();
                if (readByte != Convert.ToByte(i % 8))
                {
                    Console.WriteLine(@"error {0} must {1} real {2}", i, Convert.ToByte(i % 8), readByte);
                }
            }
        }
Exemple #4
0
        private static void TestByBuffer(MemoryStreamLongSize stream)
        {
            var count = 2000;
            for (int i = 0; i < count; i++)
            {
                var buffer = Enumerable.Range(0, 10).Select(j => (Convert.ToByte(j % 8))).ToArray();
                stream.Write(buffer, 0, buffer.Length);
                //  if(i%1000000==0)
                //Console.WriteLine(GC.GetTotalMemory(false)/1024/1024);
            }

            stream.Seek(0, SeekOrigin.Begin);
            for (int i = 0; i < count; i++)
            {
                var buffer = new byte[10];
                stream.Read(buffer, 0, buffer.Length);
                for (int j = 0; j < 10; j++)
                {
                    if (buffer[j] != (Convert.ToByte(j % 8)))
                        Console.WriteLine("error {0} must {1} real {2}", 10 * i + j, Convert.ToByte(j % 8), buffer[j]);

                }
            }
        }