コード例 #1
0
        /// <summary>
        /// Writes all of the dirty blocks passed onto the disk subsystem. Also computes the checksum for the data.
        /// </summary>
        /// <param name="currentEndOfCommitPosition">the last valid byte of the file system where this data will be appended to.</param>
        /// <param name="stream">the source of the data to dump to the disk</param>
        /// <param name="length">The number by bytes to write to the file system.</param>
        /// <param name="waitForWriteToDisk">True to wait for a complete commit to disk before returning from this function.</param>
        public void Write(long currentEndOfCommitPosition, MemoryPoolStreamCore stream, long length, bool waitForWriteToDisk)
        {
            byte[] buffer          = m_bufferQueue.Dequeue();
            long   endPosition     = currentEndOfCommitPosition + length;
            long   currentPosition = currentEndOfCommitPosition;

            while (currentPosition < endPosition)
            {
                IntPtr ptr;
                int    streamLength;
                stream.ReadBlock(currentPosition, out ptr, out streamLength);
                int subLength = (int)Math.Min(streamLength, endPosition - currentPosition);
                Footer.ComputeChecksumAndClearFooter(ptr, m_fileStructureBlockSize, subLength);
                Marshal.Copy(ptr, buffer, 0, subLength);
                WriteRaw(currentPosition, buffer, subLength);

                currentPosition += subLength;
            }
            m_bufferQueue.Enqueue(buffer);

            if (waitForWriteToDisk)
            {
                FlushFileBuffers();
            }
            else
            {
                using (m_isUsingStream.EnterReadLock())
                {
                    m_stream.Flush(false);
                }
            }
        }
コード例 #2
0
 public void TestConstructor()
 {
     Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
     using (MemoryPoolStreamCore ms = new MemoryPoolStreamCore())
     {
         Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
     }
     Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
 }
コード例 #3
0
 public void TestConstructor()
 {
     Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
     using (MemoryPoolStreamCore ms = new MemoryPoolStreamCore())
     {
         Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
     }
     Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
 }
コード例 #4
0
 public void TestAlignment()
 {
     Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
     using (MemoryPoolStreamCore ms = new MemoryPoolStreamCore())
     {
         BlockArguments args = new BlockArguments();
         ms.ConfigureAlignment(41211, 4096);
         Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
         args.Position = 41211;
         ms.GetBlock(args);
         Assert.AreEqual(41211L, args.FirstPosition);
         Assert.AreEqual(Globals.MemoryPool.AllocatedBytes - (41211 % 4096), args.Length);
         Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, Globals.MemoryPool.PageSize);
     }
     Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
 }
コード例 #5
0
 public void TestAllocateAndDeallocate()
 {
     Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
     using (MemoryPoolStreamCore ms = new MemoryPoolStreamCore())
     {
         BlockArguments args = new BlockArguments();
         ms.GetBlock(args);
         Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, Globals.MemoryPool.PageSize);
         ms.GetBlock(args);
         Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, Globals.MemoryPool.PageSize);
         args.Position = Globals.MemoryPool.PageSize;
         ms.GetBlock(args);
         Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 2 * Globals.MemoryPool.PageSize);
     }
     Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
 }
コード例 #6
0
 public void TestAlignment()
 {
     Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
     using (MemoryPoolStreamCore ms = new MemoryPoolStreamCore())
     {
         BlockArguments args = new BlockArguments();
         ms.ConfigureAlignment(41211, 4096);
         Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
         args.Position = 41211;
         ms.GetBlock(args);
         Assert.AreEqual(41211L, args.FirstPosition);
         Assert.AreEqual(Globals.MemoryPool.AllocatedBytes - (41211 % 4096), args.Length);
         Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, Globals.MemoryPool.PageSize);
     }
     Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
 }
コード例 #7
0
 public void TestAllocateAndDeallocate()
 {
     Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
     using (MemoryPoolStreamCore ms = new MemoryPoolStreamCore())
     {
         BlockArguments args = new BlockArguments();
         ms.GetBlock(args);
         Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, Globals.MemoryPool.PageSize);
         ms.GetBlock(args);
         Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, Globals.MemoryPool.PageSize);
         args.Position = Globals.MemoryPool.PageSize;
         ms.GetBlock(args);
         Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 2 * Globals.MemoryPool.PageSize);
     }
     Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
 }