Esempio n. 1
0
        public void DropTable(int rootPage)
        {
            MemoryPage page = _pager.ReadPage(rootPage);
            BTreeNode  node = new BTreeNode(page);

            _bTree.RemoveTree(node);
        }
Esempio n. 2
0
        public void RemoveTree(BTreeNode root)
        {
            if (root.PageType == PageTypes.LeafIndexPage || root.PageType == PageTypes.LeafTablePage)
            {
                DeleteNode(root);
                return;
            }
            if (root.PageType == PageTypes.InternalIndexPage)
            {
                foreach (BTreeCell cell in root)
                {
                    MemoryPage page = _pager.ReadPage((int)((InternalIndexCell)cell).ChildPage);
                    BTreeNode  node = new BTreeNode(page);
                    RemoveTree(node);
                }
            }
            else  // (root.PageType == PageTypes.InternalTablePage)
            {
                foreach (BTreeCell cell in root)
                {
                    MemoryPage page = _pager.ReadPage((int)((InternalTableCell)cell).ChildPage);
                    BTreeNode  node = new BTreeNode(page);
                    RemoveTree(node);
                }
            }
            MemoryPage rightPage = _pager.ReadPage((int)root.RightPage);
            BTreeNode  rightNode = new BTreeNode(rightPage);

            RemoveTree(rightNode);
            // post-order traversal
            DeleteNode(root);
        }
Esempio n. 3
0
        private void UpdateMemoryPage()
        {
            MemoryPage.Clear();
            var offset = (_memoryPageOffset * 256);

            var multiplyer = 0;

            for (var i = offset; i < 256 * (_memoryPageOffset + 1); i++)
            {
                MemoryPage.Add(new MemoryRowModel
                {
                    Offset     = ((16 * multiplyer) + offset).ToString("X").PadLeft(4, '0'),
                    Location00 = Proc.ReadMemoryValueWithoutCycle(i++).ToString("X").PadLeft(2, '0'),
                    Location01 = Proc.ReadMemoryValueWithoutCycle(i++).ToString("X").PadLeft(2, '0'),
                    Location02 = Proc.ReadMemoryValueWithoutCycle(i++).ToString("X").PadLeft(2, '0'),
                    Location03 = Proc.ReadMemoryValueWithoutCycle(i++).ToString("X").PadLeft(2, '0'),
                    Location04 = Proc.ReadMemoryValueWithoutCycle(i++).ToString("X").PadLeft(2, '0'),
                    Location05 = Proc.ReadMemoryValueWithoutCycle(i++).ToString("X").PadLeft(2, '0'),
                    Location06 = Proc.ReadMemoryValueWithoutCycle(i++).ToString("X").PadLeft(2, '0'),
                    Location07 = Proc.ReadMemoryValueWithoutCycle(i++).ToString("X").PadLeft(2, '0'),
                    Location08 = Proc.ReadMemoryValueWithoutCycle(i++).ToString("X").PadLeft(2, '0'),
                    Location09 = Proc.ReadMemoryValueWithoutCycle(i++).ToString("X").PadLeft(2, '0'),
                    Location0A = Proc.ReadMemoryValueWithoutCycle(i++).ToString("X").PadLeft(2, '0'),
                    Location0B = Proc.ReadMemoryValueWithoutCycle(i++).ToString("X").PadLeft(2, '0'),
                    Location0C = Proc.ReadMemoryValueWithoutCycle(i++).ToString("X").PadLeft(2, '0'),
                    Location0D = Proc.ReadMemoryValueWithoutCycle(i++).ToString("X").PadLeft(2, '0'),
                    Location0E = Proc.ReadMemoryValueWithoutCycle(i++).ToString("X").PadLeft(2, '0'),
                    Location0F = Proc.ReadMemoryValueWithoutCycle(i).ToString("X").PadLeft(2, '0'),
                });
                multiplyer++;
            }
        }
Esempio n. 4
0
        public static BTreeNode GetBTreeNode(Pager pager, int pageNumber)
        {
            MemoryPage page = pager.ReadPage(pageNumber);
            BTreeNode  node = new BTreeNode(page);

            return(node);
        }
Esempio n. 5
0
        private List <BTreeCell> LinearSearch(BTreeNode root, Expression expression, List <AttributeDeclaration> attributeDeclarations)
        {
            BTreeNode        startNode = FindMin(root);
            List <BTreeCell> result    = new List <BTreeCell>();
            LeafTableCell    leafCell;

            while (true)
            {
                foreach (var cell in startNode)
                {
                    leafCell = (LeafTableCell)cell;
                    if (expression == null)
                    {
                        result.Add(cell);
                    }
                    else if (expression.Calculate(attributeDeclarations, leafCell.DBRecord.GetValues()).BooleanValue == true)
                    {
                        result.Add(cell);
                    }
                }
                if (startNode.RightPage == 0)
                {
                    return(result);
                }
                MemoryPage nextpage = _pager.ReadPage((int)startNode.RightPage);
                startNode = new BTreeNode(nextpage);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// <para>
        /// to find cells that satisfy:
        ///  - starting from `startNode`
        ///  - ends in `upperBound`
        ///      - might be inclusive depending on `isIncludeUpperBound`
        ///  - satisfying `condition`
        /// </para>
        /// <para>`attributeDeclarations` := the names of the columns</para>
        /// </summary>
        /// <param name="startNode"></param>
        /// <param name="condition"></param>
        /// <param name="attributeDeclarations">the names of the columns</param>
        /// <param name="upperBound"></param>
        /// <param name="isIncludeUpperBound"></param>
        /// <returns></returns>
        private List <BTreeCell> FindCells(BTreeNode startNode, Expression condition, List <AttributeDeclaration> attributeDeclarations, AtomValue upperBound, bool isIncludeUpperBound)
        {
            List <BTreeCell> result = new List <BTreeCell>();
            LeafTableCell    leafCell;

            while (true)
            {
                foreach (var cell in startNode)
                {
                    if (((cell.Key.GetValues()[0] > upperBound).BooleanValue && isIncludeUpperBound) ||
                        ((cell.Key.GetValues()[0] >= upperBound).BooleanValue && !isIncludeUpperBound))
                    {
                        return(result);
                    }
                    leafCell = (LeafTableCell)cell;

                    if (condition.Calculate(attributeDeclarations, leafCell.DBRecord.GetValues()).BooleanValue == true)
                    {
                        result.Add(cell);
                    }
                }
                if (startNode.RightPage == 0)
                {
                    return(result);
                }
                MemoryPage nextpage = _pager.ReadPage((int)startNode.RightPage);
                startNode = new BTreeNode(nextpage);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Resets a memory page to defaults, deletes that page's swap file and
        /// may mark the page as free in physical memory
        /// </summary>
        /// <param name="page">The <see cref="MemoryPage"/> to reset</param>
        public void ResetPage(MemoryPage page)
        {
            if (page.isValid == true)
            {
                // Make this page as availble in physical memory
                uint i = page.addrPhysical / CPU.pageSize;
                Debug.Assert(i < freePhysicalPages.Length);                 //has to be
                freePhysicalPages[(int)i] = true;
            }

            //Reset to reasonable defaults
            page.isDirty            = false;
            page.addrPhysical       = 0;
            page.pidOwner           = 0;
            page.pageFaults         = 0;
            page.accessCount        = 0;
            page.lastAccessed       = DateTime.Now;
            page.addrProcessIndex   = 0;
            page.heapAllocationAddr = 0;

            // Delete this page's swap file
            string filename = System.Environment.CurrentDirectory + "/page" + page.pageNumber + "." + page.addrVirtual + ".xml";

            File.Delete(filename);
        }
Esempio n. 8
0
        // recycle page to free list
        private void DeleteNode(BTreeNode node)
        {
            MemoryPage page = node.RawPage;

            node.IsDisabled = true;
            _freeList.RecyclePage(page);
        }
        public void AddPageTest()
        {
            PhysicalMemory mem = new PhysicalMemory(10);
            MemoryPage     m   = new MemoryPage(0, 0, "Unit Test", -1);

            mem.AddPage(m, 0);
            Assert.IsTrue(mem.Pages.Contains(m));
        }
Esempio n. 10
0
 /// <summary>
 /// Creates a new call stack
 /// </summary>
 /// <param name="memoryManager">The memory manager</param>
 /// <param name="managedObjectReferences">The object references</param>
 /// <param name="size">The maximum number of entries in the call stack</param>
 public CallStack(MemoryManager memoryManager, ManagedObjectReferences managedObjectReferences, int size)
 {
     this.memoryManager           = memoryManager;
     this.managedObjectReferences = managedObjectReferences;
     this.Size            = size;
     this.callStackMemory = memoryManager.CreatePage(Constants.NativePointerSize + size * CallStackEntrySize);
     NativeHelpers.SetLong(this.TopPointer, 0, this.CallStackStart.ToInt64());
 }
Esempio n. 11
0
 /// <summary>
 /// Constructor for memory window that takes the window instance that is creating this window
 /// PLEASE NOTE: This constructor should always be used so data can be passed back to the parent window
 /// </summary>
 /// <param name="parentWindow">The window that is creating this window </param>
 /// <param name="currentPage"> The memory page to be displayed in the window </param>
 public MemoryWindow(MainWindow parentWindow, MemoryPage currentPage) : this()
 {
     this.mainParentWindow = parentWindow;
     this.currentPage      = currentPage;
     currentInstance       = this;
     SetMemoryWindowInstance();
     PopulateDataView();
 }
Esempio n. 12
0
        public static void TestLeafTableNode()
        {
            string dbPath = "./testdbfile.minidb";

            File.Delete(dbPath);
            Pager      pager = new Pager(dbPath);
            MemoryPage page  = pager.GetNewPage();

            BTreeNode node = new BTreeNode(page, PageTypes.LeafTablePage);

            // init record
            DBRecord      keyRecord     = null;
            DBRecord      record        = null;
            LeafTableCell leafTableCell = null;

            keyRecord = GetTestBRecord(1);
            record    = GetTestBRecord(175.1, 1, "Person1", "000001", 18);
            // build cell + insert to node
            leafTableCell = new LeafTableCell(keyRecord, record);
            node.InsertBTreeCell(leafTableCell);

            keyRecord = GetTestBRecord(2);
            record    = GetTestBRecord(165.1, 2, "Person2", "000002", 19);
            // build cell + insert to node
            leafTableCell = new LeafTableCell(keyRecord, record);
            node.InsertBTreeCell(leafTableCell);

            keyRecord = GetTestBRecord(3);
            record    = GetTestBRecord(165.3, 3, "Person3", "000003", 20);
            // build cell + insert to node
            leafTableCell = new LeafTableCell(keyRecord, record);
            node.InsertBTreeCell(leafTableCell);

            keyRecord = GetTestBRecord(4);
            record    = GetTestBRecord(175.9, 4, "Person4", "000004", 21);
            // build cell + insert to node
            leafTableCell = new LeafTableCell(keyRecord, record);
            node.InsertBTreeCell(leafTableCell);

            keyRecord = GetTestBRecord(5);
            record    = GetTestBRecord(175.0, 5, "Person5", "000005", 22);
            // build cell + insert to node
            leafTableCell = new LeafTableCell(keyRecord, record);
            node.InsertBTreeCell(leafTableCell);
            // visualize
            BTreeNodeHelper.VisualizeIntegerTree(pager, node);

            keyRecord = GetTestBRecord(6);
            record    = GetTestBRecord(172.1, 6, "Person6", "000006", 23);
            // build cell + insert to node
            leafTableCell = new LeafTableCell(keyRecord, record);
            node.InsertBTreeCell(leafTableCell);
            // visualize
            BTreeNodeHelper.VisualizeIntegerTree(pager, node);

            pager.Close();
        }
Esempio n. 13
0
        public void SwapOutTest()
        {
            PhysicalMemory mem   = new PhysicalMemory(10);
            PageTable      table = new PageTable(0);
            MemoryPage     m     = new MemoryPage(0, 0, "Unit Test", -1);

            mem.AddPage(m, 0);
            m.SwapOut(0, 0);
            Assert.IsTrue(table.Entries[0].SwappedOut);
        }
 /// <summary>
 /// Constructor for a page table entry
 /// </summary>
 /// <param name="frameNumber"> the frame number of this entry</param>
 /// <param name="logicalAddress"> the logical address of this entry</param>
 /// <param name="physicalAddress"> the physical address of this entry</param>
 /// <param name="swappedOut"> whether this page is swapped out</param>
 /// <param name="page"> the memory page associated with this entry</param>
 public PageTableEntry(int frameNumber, int logicalAddress, int physicalAddress, bool swappedOut, MemoryPage page)
 {
     this.frameNumber     = frameNumber;
     this.logicalAddress  = logicalAddress;
     this.physicalAddress = physicalAddress;
     this.swappedOut      = swappedOut;
     faults           = 0;
     this.page        = page;
     page.FrameNumber = frameNumber;
 }
Esempio n. 15
0
        protected override void Dispose(bool disposing)
        {
            if (this.memoryPage != null)
            {
                this.WriteBuffer();
                Pool.ReturnPage(this.memoryPage);
                this.memoryPage = null;
            }

            base.Dispose(disposing);
        }
Esempio n. 16
0
 public MemoryViewModel(IMemory memory)
 {
     this.memory              = memory;
     page                     = new MemoryPage();
     addresses                = new Addresses(memory.Size - 0x100);
     Address                  = new Address();
     Address.PropertyChanged += Address_PropertyChanged;
     Address.Maximum          = memory.Size - 0x100;
     size                     = (int)memory.Size / 1024;
     fillingFactor            = memory.FillingFactor;
     fillingFactorPercents    = fillingFactor / (double)memory.Size * 100.0;
 }
Esempio n. 17
0
        public PagedMemory(UInt32 totalPageCount, UInt32 pageSize, UInt32 contigPageCount)
        {
            this.pageSize = pageSize;
            AllPages = new MemoryPage[totalPageCount];
            CurrentPages = new MemoryPage[contigPageCount];

            for (var idx = 0; idx < totalPageCount; idx++)
                AllPages[idx] = new MemoryPage(pageSize, false);

            for (var idx = 0; idx < contigPageCount; idx++)
                CurrentPages[idx] = AllPages[idx];
        }
Esempio n. 18
0
            public void ReturnPage(MemoryPage page)
            {
                for (var i = 0; i < this.pool.Length; i++)
                {
                    if (Interlocked.CompareExchange(ref this.pool[i], page, null) == null)
                    {
                        return;
                    }
                }

                page.Dispose();
            }
        public void RequestMemoryPageTest()
        {
            PhysicalMemory mem = new PhysicalMemory(10);
            MemoryPage     p1  = new MemoryPage(0, 0, "Unit Test", -1);
            MemoryPage     p2  = new MemoryPage(1, 1 * MemoryPage.PAGE_SIZE, "Unit Test", -1);

            mem.AddPage(p1, 0);
            mem.AddPage(p2, 1);
            MemoryPage req = mem.RequestMemoryPage(1);

            Assert.AreEqual(p2, req);
        }
Esempio n. 20
0
        public unsafe BufferedBinaryWriter(Stream output, Encoding encoding, bool leaveOpen)
            : base(output, encoding, leaveOpen)
        {
            this.memoryPage = Pool.GetPage();

            this.basePtr = this.memoryPage.BasePtr;
            this.endPtr  = this.memoryPage.EndPtr;

            this.ptr              = this.basePtr;
            this.encoding         = encoding;
            this.encoder          = encoding.GetEncoder();
            this.charMaxByteCount = encoding.IsSingleByte ? 1 : encoding.GetMaxByteCount(1);
        }
Esempio n. 21
0
        public unsafe BufferedBinaryWriter(Stream output, Encoding encoding)
            : base(output, encoding)
        {
            this.memoryPage = Pool.GetPage();

            this.basePtr = this.memoryPage.BasePtr;
            this.endPtr = this.memoryPage.EndPtr;

            this.ptr = this.basePtr;
            this.encoding = encoding;
            this.encoder = encoding.GetEncoder();
            this.charMaxByteCount = encoding.IsSingleByte ? 1 : encoding.GetMaxByteCount(1);
        }
Esempio n. 22
0
        private void _Update()
        {
            leftMemory  = files[IndexOfTheSelectedLeftFile].memory;
            rightMemory = files[IndexOfTheSelectedRightFile].memory;

            List <long> addressesOfDifferences;

            if (Memory.Equals(leftMemory, rightMemory, out addressesOfDifferences))
            {
                Status        = Resources.FilesAreEquals;
                FilesAreEqual = true;
                Differences   = "";
            }
            else
            {
                Status        = Resources.FilesAreNotEquals;
                FilesAreEqual = false;
                Differences   = string.Format(Resources.Difference, addressesOfDifferences.Count);
            }


            addressesOfDiffPages = new SortedSet <long>();

            foreach (var address in addressesOfDifferences)
            {
                addressesOfDiffPages.Add((address / Page.Size) * Page.Size);
            }


            if (!init)
            {
                init      = true;
                leftPage  = new MemoryPage();
                rightPage = new MemoryPage();
                addresses = new Addresses(leftMemory.Size - 0x100);
                Address   = new Address();
                Address.PropertyChanged += Address_PropertyChanged;
                Address.Maximum          = leftMemory.Size - 0x100;
                AddressesOfDiffPages     = new ObservableCollection <string>();
            }
            AddressesOfDiffPages.Clear();
            foreach (var address in addressesOfDiffPages)
            {
                var lenght = Address.Maximum.ToString("X").Length;
                AddressesOfDiffPages.Add(address.ToString("X" + lenght));
            }
            IndexOfTheSelectedAddress = 0;
            Update();
        }
Esempio n. 23
0
        // allocate a new node from free list or from pager
        private BTreeNode GetNewNode(PageTypes nodeType)
        {
            // allocate
            MemoryPage newPage = _freeList.AllocatePage();

            if (newPage == null)
            {
                newPage = _pager.GetNewPage();
            }

            // initialize node
            BTreeNode node = new BTreeNode(newPage, nodeType);

            return(node);
        }
Esempio n. 24
0
        private void SwapInPage(int pageNumber)
        {
            int progindex =
                mainParentWindow.ProgramList.IndexOf(
                    mainParentWindow.ProgramList.Where(x => x.Name == mainParentWindow.currentProgram).FirstOrDefault());
            int pageIndex = 0;

            for (int i = 0; i < progindex; i++)
            {
                progindex += mainParentWindow.ProgramList[i].Pages;
            }
            pageIndex  += pageNumber;
            currentPage = mainParentWindow.Memory.RequestMemoryPage(pageNumber);
            this.InvalidateVisual();
        }
Esempio n. 25
0
        static void TestFreeList()
        {
            string dbPath = "./testdbfile.minidb";

            File.Delete(dbPath);

            Pager pager = new Pager(dbPath, 4096, 100);

            List <MemoryPage> pageList = new List <MemoryPage>();

            pageList.Add(pager.GetNewPage());  // page #2
            pageList.Add(pager.GetNewPage());  // page #3
            pageList.Add(pager.GetNewPage());  // page #4
            pageList.Add(pager.GetNewPage());  // page #5

            FreeList freeList = new FreeList(pager);

            // test initialization
            MemoryPage newPage = null;

            newPage = freeList.AllocatePage();  // freeList is now empty
            Assert.Null(newPage);

            // recycle pages
            // MemoryPage tempPage = pager.ReadPage(3);
            freeList.RecyclePage(pageList[2]);  // freeList->4
            freeList.RecyclePage(pageList[1]);  // freeList->3->4
            freeList.RecyclePage(pageList[3]);  // freeList->5->3->4

            // fetch page from free list
            newPage = freeList.AllocatePage();  // freeList->3->4
            Assert.Equal(5, newPage.PageNumber);
            newPage = freeList.AllocatePage();  // freeList->4
            Assert.Equal(3, newPage.PageNumber);

            // recycle a page
            freeList.RecyclePage(pageList[3]);  // freeList->5->4

            // fetch remaining pages
            newPage = freeList.AllocatePage();  // freeList->4
            Assert.Equal(5, newPage.PageNumber);
            newPage = freeList.AllocatePage();  // freeList->null
            Assert.Equal(4, newPage.PageNumber);
            newPage = freeList.AllocatePage();  // freeList->null
            Assert.Null(newPage);

            pager.Close();
        }
Esempio n. 26
0
        /// <summary>
        /// This function allocates memory for processes
        /// </summary>
        /// <param name="proc">reference to the process to allocate memory too</param>
        public void AllocateProcessMemory(ref SimulatorProcess proc)
        {
            if (proc == null)
            {
                MessageBox.Show("Can't allocate memory for a null process");
                return;
            }
            dynamic        wind = GetMainWindowInstance();
            PhysicalMemory mem  = wind.Memory;

            for (int i = 0; i < proc.ProcessMemory; i++)
            {
                MemoryPage m = new MemoryPage(i, i * MemoryPage.PAGE_SIZE, proc.Program.Name, proc.ProcessID);
                mem.AddPage(m, i);
            }
        }
Esempio n. 27
0
        private uint ProcessAddrToPhysicalAddrHelper(MemoryPage page, bool dirtyFlag, uint pageOffset)
        {
            // Get the page offset
            uint virtualIndex = page.addrVirtual + pageOffset;

            // Update Flags for this process
            page.isDirty = dirtyFlag || page.isDirty;
            page.accessCount++;
            page.lastAccessed = DateTime.Now;

            // Take this new "virtual" address (relative to all addressable memory)
            // and translate it to physical ram.  Page Faults may occur inside this next call.
            uint physicalIndex = VirtualAddrToPhysical(page, virtualIndex);

            return(physicalIndex);
        }
Esempio n. 28
0
        // find the minimal node (leftest leaf node) from the given tree of root node `root`
        private BTreeNode FindMin(BTreeNode root)
        {
            BTreeNode         child;
            InternalTableCell childCell;

            if (root.PageType == PageTypes.LeafTablePage)
            {
                return(root);
            }
            // childCell = (InternalTableCell)root.GetBTreeCell(root.CellOffsetArray[0]);
            childCell = (InternalTableCell)root[0];
            MemoryPage nextpage = _pager.ReadPage((int)childCell.ChildPage);

            child = new BTreeNode(nextpage);

            return(FindMin(child));
        }
Esempio n. 29
0
        static void TestPager()
        {
            string dbPath = "./testdbfile.minidb";

            File.Delete(dbPath);

            Pager pager = new Pager(dbPath, 4096, 4);

            Assert.Equal(pager.PageCount, 1);

            pager.ExtendNumberOfPages();
            Assert.Equal(pager.PageCount, 2);

            MemoryPage page = pager.ReadPage(1);

            page.Data[2] = 114;
            page.Data[3] = 5;
            page.Data[4] = 14;

            pager.WritePage(page);
            MemoryPage page1 = pager.ReadPage(1);

            Assert.Equal(page.Data[2], page1.Data[2]);
            Assert.Equal(page.Data[3], page1.Data[3]);
            Assert.Equal(page.Data[4], page1.Data[4]);

            // it will save all dirty pages and remove all pages from recording
            // after that, any MemoryPage returned from this `pager` will no longer legal to use
            pager.Close();

            pager.Open(dbPath);
            // another page also with page number 1
            page1 = pager.ReadPage(1);

            // test if preventing buffer duplication
            Assert.Equal(page.Data[2], page1.Data[2]);
            Assert.Equal(page.Data[3], page1.Data[3]);
            Assert.Equal(page.Data[4], page1.Data[4]);

            // test if the two page pointing to the same buffer
            Assert.Equal(page1.Data[100], 0);
            page.Data[100] = 1;
            Assert.Equal(page1.Data[100], 1);

            pager.Close();
        }
Esempio n. 30
0
        public void ZeroMemoryTest()
        {
            MemoryPage m     = new MemoryPage(0, 0, "Unit Test", -1);
            int        count = 0;

            m.ZeroMemory();
            for (int i = 0; i < MemoryPage.PAGE_SIZE / 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    if (m.Data[i].GetByte(j) == 0x00)
                    {
                        count++;
                    }
                }
            }
            Assert.IsTrue(count == 256);
        }
Esempio n. 31
0
        /// <summary>
        /// Swaps in the specified <see cref="MemoryPage"/> from disk.  Currently implemented as XML for fun.
        /// </summary>
        /// <param name="winner">The <see cref="MemoryPage"/> that is being swapped in</param>
        public void SwapIn(MemoryPage winner)
        {
            // Generate a filename based on address and page number
            string filename = System.Environment.CurrentDirectory + "/page" + winner.pageNumber + "-" + winner.addrVirtual + ".xml";

            if (File.Exists(filename) && winner.isValid == false)
            {
                //BinaryFormatter ser = new BinaryFormatter();
                //Stream reader = new FileStream(filename, FileMode.Open);

                XmlSerializer ser    = new XmlSerializer(typeof(MemoryPageValue));
                Stream        fs     = new FileStream(filename, FileMode.Open);
                XmlReader     reader = new XmlTextReader(fs);

                // Load the MemoryPageValue in from Disk!
                MemoryPageValue pageValue = (MemoryPageValue)ser.Deserialize(reader);

                // Copy the bytes from Physical Memory so we don't pageFault in a Fault Hander
                for (int i = 0; i < CPU.pageSize; i++)
                {
                    CPU.physicalMemory[winner.addrPhysical + i] = pageValue.memory[i];
                }

                //Console.WriteLine("Swapping in page {0} at physical memory {1}",winner.pageNumber, winner.addrPhysical);

                winner.accessCount  = pageValue.accessCount;
                winner.lastAccessed = pageValue.lastAccessed;

                pageValue = null;

                reader.Close();
                fs.Close();
                File.Delete(filename);
            }
            else             //no swap file, do nothing
            {
                //Console.WriteLine(filename + " doesn't exist");
            }

            // We are now in memory and we were involved in Page Fault
            winner.isValid = true;
            winner.pageFaults++;
        }
Esempio n. 32
0
        public static byte[] GetMemoryPage(uint pageIdx, DoneNotif notifFn)
        {
            if (!currentlyPaused)
            {
                // Don't allow reading while the game is running...
                return(null);
            }

            cacheMutex.WaitOne();
            MemoryPage entry;

            if (!memDict.TryGetValue(pageIdx, out entry))
            {
                entry = null;
            }

            if (entry == null)
            {
                var newPage = new MemoryPage();
                newPage.pauseIdx = 0;
                newPage.data     = null;
                newPage.waiters  = new List <DoneNotif>();
                memDict.Add(pageIdx, newPage);
                entry = newPage;
            }

            if (entry.pauseIdx < pauseIndex)
            {
                uint PAGE_SIZE = GetMemoryPageSize();
                sendReadMem(pageIdx * PAGE_SIZE, PAGE_SIZE);
                entry.pauseIdx = pauseIndex;

                if (notifFn != null)
                {
                    entry.waiters.Add(notifFn);
                }
            }

            cacheMutex.ReleaseMutex();
            return(entry.data);
        }
Esempio n. 33
0
 public SpectrumDisplay(MemoryPage memoryPage)
 {
     this.memoryPage = memoryPage;
 }
        /// <summary>
        /// Creates a new page
        /// </summary>
        /// <param name="minSize">The minimum size required by the page</param>
        private MemoryPage CreatePage(int minSize)
        {
            //Align the size of the page to page sizes.
            int size = (minSize + (this.pageSize - 1) / this.pageSize) * this.pageSize;

            //Allocate writable & readable memory
            var memory = WinAPI.VirtualAlloc(
                IntPtr.Zero,
                (uint)size,
                WinAPI.AllocationType.Commit,
                WinAPI.MemoryProtection.ReadWrite);

            var page = new MemoryPage(memory, size);
            this.pages.Add(page);
            return page;
        }
Esempio n. 35
0
            public void ReturnPage(MemoryPage page)
            {
                for (var i = 0; i < this.pool.Length; i++)
                {
                    if (Interlocked.CompareExchange(ref this.pool[i], page, null) == null)
                    {
                        return;
                    }
                }

                page.Dispose();
            }
 /// <summary>
 /// Adds the given page to the list of pages and makes it the active one
 /// </summary>
 /// <param name="page">The page</param>
 public void AddPage(MemoryPage page)
 {
     this.pages.Add(page);
     this.ActivePage = page;
 }