예제 #1
0
        /// <summary>
        /// Reads an entire page at the provided location. Also computes the checksum information.
        /// </summary>
        /// <param name="position">The stream position. May be any position inside the desired block</param>
        /// <param name="locationToCopyData">The place where to write the data to.</param>
        public void Read(long position, IntPtr locationToCopyData)
        {
            byte[] buffer    = m_bufferQueue.Dequeue();
            int    bytesRead = ReadRaw(position, buffer, buffer.Length);

            if (bytesRead < buffer.Length)
            {
                Array.Clear(buffer, bytesRead, buffer.Length - bytesRead);
            }

            Marshal.Copy(buffer, 0, locationToCopyData, buffer.Length);

            m_bufferQueue.Enqueue(buffer);

            Footer.WriteChecksumResultsToFooter(locationToCopyData, m_fileStructureBlockSize, buffer.Length);
        }
        public void Test()
        {
            MemoryPoolTest.TestMemoryLeak();
            int x = 0;
            ResourceQueue<string> queue = new ResourceQueue<string>(() => (x++).ToString(), 3, 4);

            x = 10;

            Assert.AreEqual(queue.Dequeue(), "0");
            Assert.AreEqual(queue.Dequeue(), "1");
            Assert.AreEqual(queue.Dequeue(), "2");
            Assert.AreEqual(queue.Dequeue(), "10");
            Assert.AreEqual(queue.Dequeue(), "11");

            queue.Enqueue("0");
            queue.Enqueue("1");
            Assert.AreEqual(queue.Dequeue(), "0");
            queue.Enqueue("3");
            Assert.AreEqual(queue.Dequeue(), "1");
            Assert.AreEqual(queue.Dequeue(), "3");
            Assert.AreEqual(queue.Dequeue(), "12");

            queue.Enqueue("1");
            queue.Enqueue("2");
            queue.Enqueue("3");
            queue.Enqueue("4");
            queue.Enqueue("5");
            Assert.AreEqual(queue.Dequeue(), "1");
            Assert.AreEqual(queue.Dequeue(), "2");
            Assert.AreEqual(queue.Dequeue(), "3");
            Assert.AreEqual(queue.Dequeue(), "4");
            Assert.AreEqual(queue.Dequeue(), "13");
            MemoryPoolTest.TestMemoryLeak();
        }
예제 #3
0
        public void Test()
        {
            MemoryPoolTest.TestMemoryLeak();
            int x = 0;
            ResourceQueue <string> queue = new ResourceQueue <string>(() => (x++).ToString(), 3, 4);

            x = 10;

            Assert.AreEqual(queue.Dequeue(), "0");
            Assert.AreEqual(queue.Dequeue(), "1");
            Assert.AreEqual(queue.Dequeue(), "2");
            Assert.AreEqual(queue.Dequeue(), "10");
            Assert.AreEqual(queue.Dequeue(), "11");

            queue.Enqueue("0");
            queue.Enqueue("1");
            Assert.AreEqual(queue.Dequeue(), "0");
            queue.Enqueue("3");
            Assert.AreEqual(queue.Dequeue(), "1");
            Assert.AreEqual(queue.Dequeue(), "3");
            Assert.AreEqual(queue.Dequeue(), "12");

            queue.Enqueue("1");
            queue.Enqueue("2");
            queue.Enqueue("3");
            queue.Enqueue("4");
            queue.Enqueue("5");
            Assert.AreEqual(queue.Dequeue(), "1");
            Assert.AreEqual(queue.Dequeue(), "2");
            Assert.AreEqual(queue.Dequeue(), "3");
            Assert.AreEqual(queue.Dequeue(), "4");
            Assert.AreEqual(queue.Dequeue(), "13");
            MemoryPoolTest.TestMemoryLeak();
        }