Esempio n. 1
0
        public void Random(Excel data)
        {
            Block      current;
            int        END_OF_FILE          = -1;
            int        i                    = 0;
            int        TerminateApplication = -999;
            int        First_Page_Loads     = 0;
            int        Page_Hits            = 0;
            int        Page_Faults          = 0;
            bool       Added_Succesfully;
            List <int> TerminatedApplications = new List <int>();

            Memory MyMemory = new Memory(10, 15);

            while (data.ReadCell(i, 0) != END_OF_FILE)
            {
                current = new Block(i, data.ReadCell(i, 1), data.ReadCell(i, 0));

                if (!TerminatedApplications.Contains(current.application))
                {
                    if (current.page == TerminateApplication)
                    {
                        MyMemory.RemoveApplication(current.application);
                    }
                    else if (MyMemory.InPages(current))
                    {
                        MyMemory.UpdateUsageInPages(current, i);
                        Page_Hits++;
                    }
                    else if (MyMemory.InSwap(current))
                    {
                        MyMemory.RecallFromSwap(current);
                        Page_Faults++;
                    }
                    else
                    {
                        Added_Succesfully = MyMemory.AddRandom(current);
                        if (!Added_Succesfully)
                        {
                            Console.WriteLine("system out of memory terminating process " + current.application);
                            MyMemory.RemoveApplication(current.application);
                            TerminatedApplications.Add(current.application);
                        }
                        else
                        {
                            First_Page_Loads++;
                        }
                    }
                }



                i++;
            }

            Console.WriteLine("First_Page_Loads = " + First_Page_Loads + " Page_Faults = "
                              + Page_Faults + " Page_Hits = " + Page_Hits);
        }