Beispiel #1
0
 public void Add(MockObject mockObject)
 {
     for (int i = 0; i < Length; i++)
     {
         for (int j = 0; j < Length; j++)
             if (Storage[i, j] == null)
             {
                 Storage[i, j] = mockObject;
                 break;
             }
         break;
     }           
 }
Beispiel #2
0
        public void Allocate(MockObject mockObject)
        {
            Random rnd = new Random();
            int i = rnd.Next(Length);
            int j = rnd.Next(Length);
            bool allocationSuccess = false;

            while (!allocationSuccess)
            {
                if (Storage[i, j] == null)
                {
                    Storage[i, j] = mockObject;
                    allocationSuccess = true;
                }
                else { 
                    i = rnd.Next(Length);
                    j = rnd.Next(Length);
                }
            }
        }
        public void MakeSimulation()
        {
            Stopwatch mutatorStopwatch = new Stopwatch();
            TimeSpan mutatorTime = new TimeSpan(0, 0, 0);
            Stopwatch collectorStopwatch = new Stopwatch();
            TimeSpan collectorTime = new TimeSpan(0, 0, 0);
            TimeSpan totalTime = new TimeSpan(0, 0, 0);

            int m = 0;
            int s = 0;
            int ms = 0;

            collectorTime = new TimeSpan(0, 0, m, s, ms);

            collectorWorkTime.Text = String.Format("{0}:{1}:{2}",
                collectorTime.Minutes, collectorTime.Seconds, collectorTime.Milliseconds);

            GarbageCollector collector = new GarbageCollector();

            if (radioButton.IsChecked == true)
                collector = new MarkSweepCollector();
            if (radioButton1.IsChecked == true)
                collector = new CopyingCollector();
            if (radioButton2.IsChecked == true)
                collector = new ReferenceCountingCollector();

            heap = new MockHeap(dimension);

            int objsCount = objectsAmount;

            // mutator stopwatch
            mutatorStopwatch.Start();

            MockObject mo = null;
            MarkSweepCollector msc = new MarkSweepCollector();
            do
            {
                if (objsCount != 0)
                {
                    int i = 0;
                    while (i < 5)
                    {
                        mo = new MockObject(objsCount);
                        objsCount--;
                        heap = AllocateObject(mo, heap);
                        i++;
                        Thread.Sleep(50);
                        ReDraw();
                        objectsInMemory.Text = "" + heap.ObjectsInMemory();
                        PrintToConsole();
                    }
                }
                heap = MutateHeap(heap);
                PrintToConsole();

                // mutaotr time stop
                mutatorStopwatch.Stop();
                m = mutatorStopwatch.Elapsed.Minutes + mutatorTime.Minutes;
                s = mutatorStopwatch.Elapsed.Seconds + mutatorTime.Seconds;
                ms = mutatorStopwatch.Elapsed.Milliseconds + mutatorTime.Milliseconds;

                mutatorTime = new TimeSpan(0, 0, m, s, ms);

                mutatorWorkTime.Text = String.Format("{0}:{1}:{2}", m, s, ms);
                // total time stop
                m = totalTime.Minutes + mutatorStopwatch.Elapsed.Minutes;
                s = totalTime.Seconds + mutatorStopwatch.Elapsed.Seconds;
                ms = totalTime.Milliseconds + mutatorStopwatch.Elapsed.Milliseconds;

                totalTime = new TimeSpan(0, 0, m, s, ms);

                totalWorkTime.Text = String.Format("{0}:{1}:{2}", m, s, ms);

                collectorStopwatch.Start();
                heap = collector.CollectGarbage(heap);

                // collector time stop
                collectorStopwatch.Stop();
                m = collectorStopwatch.Elapsed.Minutes + collectorTime.Minutes;
                s = collectorStopwatch.Elapsed.Seconds + collectorTime.Seconds;
                ms = collectorStopwatch.Elapsed.Milliseconds + collectorTime.Milliseconds;

                collectorTime = new TimeSpan(0, 0, m, s, ms);

                collectorWorkTime.Text = String.Format("{0}:{1}:{2}",
                    collectorTime.Minutes, collectorTime.Seconds, collectorTime.Milliseconds);

                // total time stop
                m = totalTime.Minutes + collectorStopwatch.Elapsed.Minutes;
                s = totalTime.Seconds + collectorStopwatch.Elapsed.Seconds;
                ms = totalTime.Milliseconds + collectorStopwatch.Elapsed.Milliseconds;

                totalTime = new TimeSpan(0, 0, m, s, ms);

                totalWorkTime.Text = String.Format("{0}:{1}:{2}", m, s, ms);


                PrintToConsole();
                ReDraw();
                objectsInMemory.Text = "" + heap.ObjectsInMemory();

            } while (!heap.IsEmpty());

            collctorSimulationTime = collectorTime;
        }
 public MockHeap AllocateObject(MockObject o, MockHeap h)
 {
     h.Allocate(o);
     return h;
 }
Beispiel #5
0
 public MockHeap(int elementsAmount)
 {
     Length = elementsAmount;
     Storage = new MockObject[Length, Length];
 }