예제 #1
0
        public static void RunTest(object threadInfoObj)
        {
            
            // Allocate the objects.
            lifeTimeManager = new ObjectLifeTimeManager();                                    
            LifeTimeStrategy ltStrategy;           

            int threadMediumLifeTime = mediumLifeTime;
            int threadShortLifeTime = shortLifeTime;
            int threadMediumDataSize = mediumDataSize;
            int threadShortDataSize = shortDataSize;
            int threadMediumDataCount = mediumDataCount;
            int threadShortDataCount = shortDataCount;
            float threadPercentPinned = percentPinned;
            float threadPercentWeak = percentWeak;
            bool threadRunFinalizer = runFinalizer;
            string threadStrategy = strategy;
            string threadObjectGraph = objectGraph;                       
            
            if (threadObjectGraph.ToLower() == "tree")
            {
                lifeTimeManager.SetObjectContainer(new BinaryTreeObjectContainer<LifeTime>());   
            }
            else
            {
                lifeTimeManager.SetObjectContainer(new ArrayObjectContainer<LifeTime>());
            }
            
            lifeTimeManager.Init(threadShortDataCount + threadMediumDataCount);    
            

            if (threadStrategy.ToLower()=="random")
            {
                ltStrategy = new RandomLifeTimeStrategy(threadMediumLifeTime, threadShortLifeTime, threadMediumDataCount, threadShortDataCount);
            }
            else
            {
                // may be we need to specify the elapsed time.
                ltStrategy = new TimeBasedLifeTimeStrategy();
            }

            lifeTimeManager.LifeTimeStrategy = ltStrategy;
            lifeTimeManager.objectDied += new ObjectDiedEventHandler(objectDied);

            for (int i=0; i < threadShortDataCount + threadMediumDataCount; ++i)
            {
                bool pinned = false;
                if (threadPercentPinned!=0)
                {
                    pinned = (i % ((int)(1/threadPercentPinned))==0);
                }

                bool weak = false;
                if (threadPercentWeak!=0)
                {
                    weak = (i % ((int)(1/threadPercentWeak))==0);
                }

                ObjectWrapper oWrapper = new ObjectWrapper(threadRunFinalizer, pinned, weak);                
                if (i < threadShortDataCount)
                {
                    oWrapper.DataSize = threadShortDataSize;
                    oWrapper.LifeTime = LifeTimeENUM.Short;
                }
                else
                {
                    oWrapper.DataSize = threadMediumDataSize;
                    oWrapper.LifeTime = LifeTimeENUM.Medium;                
                }                

                lifeTimeManager.AddObject(oWrapper, i);
            }

            for (int i = 0; i < countIters; ++i)
            {
            
                // Run the test.
                lifeTimeManager.Run();
            }

        }
예제 #2
0
        private static void objectDied(LifeTime lifeTime, int index)
        {
            // put a new fresh object instead;

            LifeTimeENUM lifeTimeEnum;
            lifeTimeEnum = lifeTime.LifeTime;

            ObjectWrapper oWrapper = lifeTime as ObjectWrapper;
            bool weakReferenced = oWrapper.IsWeak();
            bool pinned = oWrapper.IsPinned();
            if (pinned)
            { 
                oWrapper.CleanUp(); 
            }
                        
            oWrapper = new ObjectWrapper(runFinalizer, pinned, weakReferenced);
            oWrapper.LifeTime = lifeTimeEnum;
            oWrapper.DataSize = lifeTime.LifeTime == LifeTimeENUM.Short ? shortDataSize : mediumDataSize;
            lifeTimeManager.AddObject(oWrapper, index);
        }
예제 #3
0
        public static void RunTest(object threadInfoObj)
        {
            // Allocate the objects.
            lifeTimeManager = new ObjectLifeTimeManager();
            LifeTimeStrategy ltStrategy;

            int    threadMediumLifeTime  = mediumLifeTime;
            int    threadShortLifeTime   = shortLifeTime;
            int    threadMediumDataSize  = mediumDataSize;
            int    threadShortDataSize   = shortDataSize;
            int    threadMediumDataCount = mediumDataCount;
            int    threadShortDataCount  = shortDataCount;
            float  threadPercentPinned   = percentPinned;
            float  threadPercentWeak     = percentWeak;
            bool   threadRunFinalizer    = runFinalizer;
            string threadStrategy        = strategy;
            string threadObjectGraph     = objectGraph;

            if (threadObjectGraph.ToLower() == "tree")
            {
                lifeTimeManager.SetObjectContainer(new BinaryTreeObjectContainer <LifeTime>());
            }
            else
            {
                lifeTimeManager.SetObjectContainer(new ArrayObjectContainer <LifeTime>());
            }

            lifeTimeManager.Init(threadShortDataCount + threadMediumDataCount);


            if (threadStrategy.ToLower() == "random")
            {
                ltStrategy = new RandomLifeTimeStrategy(threadMediumLifeTime, threadShortLifeTime, threadMediumDataCount, threadShortDataCount);
            }
            else
            {
                // may be we need to specify the elapsed time.
                ltStrategy = new TimeBasedLifeTimeStrategy();
            }

            lifeTimeManager.LifeTimeStrategy = ltStrategy;
            lifeTimeManager.objectDied      += new ObjectDiedEventHandler(objectDied);

            for (int i = 0; i < threadShortDataCount + threadMediumDataCount; ++i)
            {
                bool pinned = false;
                if (threadPercentPinned != 0)
                {
                    pinned = (i % ((int)(1 / threadPercentPinned)) == 0);
                }

                bool weak = false;
                if (threadPercentWeak != 0)
                {
                    weak = (i % ((int)(1 / threadPercentWeak)) == 0);
                }

                ObjectWrapper oWrapper = new ObjectWrapper(threadRunFinalizer, pinned, weak);
                if (i < threadShortDataCount)
                {
                    oWrapper.DataSize = threadShortDataSize;
                    oWrapper.LifeTime = LifeTimeENUM.Short;
                }
                else
                {
                    oWrapper.DataSize = threadMediumDataSize;
                    oWrapper.LifeTime = LifeTimeENUM.Medium;
                }

                lifeTimeManager.AddObject(oWrapper, i);
            }

            for (int i = 0; i < countIters; ++i)
            {
                // Run the test.
                lifeTimeManager.Run();
            }
        }