Exemplo n.º 1
0
        static void RunManager(int memoryLimit, int defragTime, MemoryFitter fitter, string input, int interval, int debugMode)
        {
            var manager = new MemoryManager(memoryLimit, defragTime, fitter, debugMode);

            CreateProcesses(manager, input);

            var stats = manager.Run(interval);

            if (debugMode != 0)
            {
                Console.WriteLine(statsHeader);
                Console.WriteLine(stats);
            }

            Console.WriteLine();

            stats = String.Format("{1, 8}; {0}", stats, manager.Fitter.name);
            output.WriteLine(stats);
            summary += stats + '\n';

            if (debugMode == 3)
            {
                Console.ReadKey();
            }
        }
Exemplo n.º 2
0
 public MemoryManager(int memoryLimit, int defragTime, MemoryFitter fitter, int debugMode)
 {
     memory          = new int[memoryLimit];
     memoryLeft      = memoryLimit;
     Fitter          = fitter;
     this.defragTime = defragTime;
     this.debugMode  = debugMode;
 }
Exemplo n.º 3
0
        static void RunProgram(Options opts)
        {
            string input;

            output = new StreamWriter(opts.OutputFile);

            if (!opts.ReadFromFile)
            {
                input = GetRandomizedProcesses(
                    opts.ProcessAmount,
                    opts.Mem.ElementAt(0),
                    opts.Mem.ElementAt(1),
                    opts.StartTime,
                    opts.Lifespan.ElementAt(0),
                    opts.Lifespan.ElementAt(1)
                    );
                File.WriteAllText("generated-input.txt", input);
            }
            else
            {
                input = File.ReadAllText(opts.InputFile);
            }

            output.WriteLine("          " + statsHeader);

            var fitters = new MemoryFitter[] {
                new BestFit(),
                new WorstFit(),
                new FirstFit(),
                new NextFit()
            };

            foreach (int i in opts.Fitters)
            {
                int j = i - 1;
                if (j < 0 || j >= fitters.Length)
                {
                    continue;
                }

                RunManager(
                    opts.MemoryLimit == null ? opts.MemoryLimitDefault : opts.MemoryLimit.Value,
                    opts.DefragTime == null ? opts.DefragTimeDefault : opts.DefragTime.Value,
                    fitters[j], input, opts.Interval, opts.DebugMode
                    );
            }

            Console.WriteLine("          " + statsHeader);
            Console.WriteLine(summary);

            output.Close();
        }