Esempio n. 1
0
        /// <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>
 /// Constructor for physical memory
 /// </summary>
 /// <param name="capacity"> capacity of physical memory in pages</param>
 public PhysicalMemory(int capacity)
 {
     this.capacity = capacity;
     pages         = new List <MemoryPage>(capacity);
     pageTable     = new PageTable(1);
     swapSpace     = new SwapSpace();
 }
        /// <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);
            }
        }
Esempio n. 4
0
        private int GetIndexSwap(int frameNumber)
        {
            dynamic   wind  = GetMainWindowInstance();
            SwapSpace swap  = wind.SwapSpace;
            int       index =
                swap.SwappedMemoryPages.IndexOf(
                    swap.SwappedMemoryPages.Where(x => x.FrameNumber == frameNumber).FirstOrDefault());

            return(index);
        }
Esempio n. 5
0
        /// <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);
            }
        }