Пример #1
0
        /// <summary>
        /// Aquire an IO Session.
        /// </summary>
        BinaryStreamIoSessionBase ISupportsBinaryStream.CreateIoSession()
        {
            if (m_disposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }
            if (RemainingSupportedIoSessions == 0)
            {
                throw new Exception("There are not any remaining IO Sessions");
            }

            BinaryStreamIoSessionBase session;

            if (m_fileHeaderBlock.IsSimplifiedFileFormat)
            {
                session = new SimplifiedIoSession(this);
            }
            else
            {
                session = new IoSession(this);
            }
            if (m_ioStream1 == null || m_ioStream1.IsDisposed)
            {
                m_ioStream1 = session;
            }
            else
            {
                m_ioStream2 = session;
            }
            return(session);
        }
Пример #2
0
        /// <summary>
        /// Creates a new DiskIoSession that can be used to read from the disk subsystem.
        /// </summary>
        /// <param name="diskIo">owner of the disk</param>
        /// <param name="ioSession">the base ioSession to use for this io session</param>
        /// <param name="file">The file that will be read from this diskIoSession</param>
        public DiskIoSession(DiskIo diskIo, BinaryStreamIoSessionBase ioSession, FileHeaderBlock header, SubFileHeader file)
        {
            if (diskIo == null)
            {
                throw new ArgumentNullException("diskIo");
            }
            if (diskIo.IsDisposed)
            {
                throw new ObjectDisposedException(diskIo.GetType().FullName);
            }
            if (ioSession == null)
            {
                throw new ArgumentNullException("ioSession");
            }
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            m_args = new BlockArguments();
            m_lastReadonlyBlock      = diskIo.LastReadonlyBlock;
            m_diskMediumIoSession    = ioSession;
            m_snapshotSequenceNumber = header.SnapshotSequenceNumber;
            m_fileIdNumber           = file.FileIdNumber;
            m_isReadOnly             = file.IsReadOnly || diskIo.IsReadOnly;
            m_blockSize = diskIo.BlockSize;
            m_diskIo    = diskIo;
            IsValid     = false;
            IsDisposed  = false;
        }
        public void TestBlocksPerSecond()
        {
            //UnmanagedMemory.Memory.UseLargePages = true;
            DebugStopwatch sw = new DebugStopwatch();

            using (MemoryPoolStream ms = new MemoryPoolStream())
            {
                using (BinaryStreamIoSessionBase io = ms.CreateIoSession())
                {
                    BlockArguments args = new BlockArguments();
                    args.Position  = ms.BlockSize * 2000L - 1;
                    args.IsWriting = true;

                    io.GetBlock(args);

                    double sec = sw.TimeEvent(() =>
                    {
                        for (int y = 0; y < 100; y++)
                        {
                            for (int x = 0; x < 2000; x++)
                            {
                                args.Position = (long)x * ms.BlockSize;
                                io.GetBlock(args);
                            }
                        }
                    });

                    System.Console.WriteLine("Get Blocks: " + (200000 / sec / 1000000).ToString("0.00 Million Per Second"));
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Aquire an IO Session.
        /// </summary>
        BinaryStreamIoSessionBase ISupportsBinaryStream.CreateIoSession()
        {
            if (m_disposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }
            if (RemainingSupportedIoSessions == 0)
            {
                throw new Exception("There are not any remaining IO Sessions");
            }

            m_ioStream1 = new SimplifiedSubFileStreamIoSession(m_stream, m_subFile, m_fileHeaderBlock);
            return(m_ioStream1);
        }
Пример #5
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 /// <filterpriority>2</filterpriority>
 public void Dispose()
 {
     if (!m_disposed)
     {
         try
         {
             if (m_ioStream1 != null)
             {
                 m_ioStream1.Dispose();
                 m_ioStream1 = null;
             }
         }
         finally
         {
             m_disposed = true; // Prevent duplicate dispose.
         }
     }
 }
Пример #6
0
 /// <summary>
 /// Releases all the resources used by the <see cref="DiskIoSession"/> object.
 /// </summary>
 public void Dispose()
 {
     if (!IsDisposed)
     {
         try
         {
             if (m_diskMediumIoSession != null)
             {
                 m_diskMediumIoSession.Dispose();
                 m_diskMediumIoSession = null;
             }
             m_diskIo = null;
         }
         finally
         {
             GC.SuppressFinalize(this);
             IsValid    = false;
             IsDisposed = true; // Prevent duplicate dispose.
         }
     }
 }
        public void Test1()
        {
            MemoryPoolTest.TestMemoryLeak();
            MemoryPoolFile file = new MemoryPoolFile(Globals.MemoryPool);

            BinaryStreamIoSessionBase session = file.CreateIoSession();

            BlockArguments blockArguments = new BlockArguments();

            blockArguments.IsWriting = true;
            blockArguments.Position  = 10000000;
            session.GetBlock(blockArguments);


            System.Console.WriteLine("Get Block\t" + StepTimer.Time(10, () =>
            {
                blockArguments.Position = 100000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 200000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 300000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 400000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 500000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 600000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 700000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 800000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 900000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 1000000;
                session.GetBlock(blockArguments);
            }));
            file.Dispose();
            MemoryPoolTest.TestMemoryLeak();
        }