/// <summary> /// This function swaps in this memory page /// </summary> /// <param name="LocationToSwap"> the physical address to swap this page in to</param> /// <param name="FrameNumber"> this pages frame number</param> public void SwapIn(int LocationToSwap, int FrameNumber) { MemoryPage temp; dynamic wind = GetMainWindowInstance(); PhysicalMemory physicalMemory = wind.Memory; // get a reference to physical memory from the main window SwapSpace swap = wind.SwapSpace; temp = swap.SwappedMemoryPages.Where(x => x.StartOffset == physicalMemory.Table.Entries[FrameNumber].Page.startOffset).FirstOrDefault(); int index = swap.SwappedMemoryPages.IndexOf(temp); if (physicalMemory.Table.Entries[FrameNumber].SwappedOut)// if this memory page is not already swapped in { physicalMemory.Table.Entries[FrameNumber].SwappedOut = false; physicalMemory.Table.Entries[FrameNumber].Faults++; for (int i = 0; i < temp.data.Length; i++) { temp.data[i].PhysicalAddress = (frameNumber * MemoryPage.PAGE_SIZE) * (i * 8); } physicalMemory.Pages.Add(temp); swap.SwappedMemoryPages.RemoveAt(GetIndexSwap(FrameNumber)); } else { MessageBox.Show("Cannot swap in page that is already in memory", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// This function swaps in this memory page /// </summary> /// <param name="LocationToSwap"> the physical address to swap this page in to</param> /// <param name="FrameNumber"> this pages frame number</param> public void SwapIn(int LocationToSwap, int FrameNumber) { MemoryPage temp; dynamic wind = GetMainWindowInstance(); PhysicalMemory physicalMemory = wind.Memory; SwapSpace swap = wind.SwapSpace; temp = swap.SwappedMemoryPages[FrameNumber]; if (physicalMemory.Table.Entries[FrameNumber].SwappedOut) { physicalMemory.Table.Entries[FrameNumber].SwappedOut = false; physicalMemory.Table.Entries[FrameNumber].Faults++; for (int i = 0; i < temp.Data.Length; i++) { temp.Data[i].PhysicalAddress = (FrameNumber * MemoryPage.PAGE_SIZE) * (i * 8); } physicalMemory.Pages.Add(temp); swap.SwappedMemoryPages.RemoveAt(GetIndexSwap(FrameNumber)); } else { MessageBox.Show("Cannot swap in page that is already in memory", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); } }
private int GetIndexMemory(int frameNumber) { dynamic wind = GetMainWindowInstance(); PhysicalMemory memory = wind.Memory; int index = memory.Pages.IndexOf(memory.Pages.Where(x => x.FrameNumber == frameNumber).FirstOrDefault()); return(index); }
/// <summary> /// Populates the data in this page with its initial value (0) /// </summary> private void PopulateData() { dynamic wind = GetMainWindowInstance(); PhysicalMemory mem = wind.Memory; int pageCount = mem.Table.Entries.Count; for (int i = 0; i < data.Length; i++) { if (data[i] == null) { data[i] = new MemorySegment((pageCount * MemoryPage.PAGE_SIZE) + (i * 8)); data[i].LogicalAddress = i * 8; } } }
/// <summary> /// This function swaps out this memory page /// </summary> /// <param name="LocationToSwap"> the physical address to swap from</param> /// <param name="FrameNumber"> this page's frame number</param> public void SwapOut(int LocationToSwap, int FrameNumber) { MemoryPage temp; dynamic wind = GetMainWindowInstance(); PhysicalMemory physicalMemory = wind.Memory; // get a reference to physical memory from the main window SwapSpace swap = wind.SwapSpace; temp = physicalMemory.Pages[GetIndexMemory(FrameNumber)]; if (!physicalMemory.Table.Entries[FrameNumber].SwappedOut) // if this memory page is not already swapped out { physicalMemory.Table.Entries[FrameNumber].SwappedOut = true; physicalMemory.Table.Entries[FrameNumber].Faults++; physicalMemory.Pages.RemoveAt(GetIndexMemory(FrameNumber)); swap.SwappedMemoryPages.Add(temp); } else { MessageBox.Show("Cannot swap out page that is already swapped out", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); } }