Exemple #1
0
        public void TestPool(IObjectPool <DummyPoolable> pool)
        {
            var sw = new Stopwatch();
            //while (true) {
            int gen0 = GC.CollectionCount(0);

            sw.Restart();
            Task.WaitAll(Enumerable.Range(0, Environment.ProcessorCount * 2).Select(_ => Task.Run(() =>
            {
                for (int i = 0; i < 1000000; i++)
                {
                    var x1 = pool.Allocate();
                    var x2 = pool.Allocate();
                    Interlocked.MemoryBarrier();
                    //Thread.SpinWait(500);
                    pool.Free(x1);
                    pool.Free(x2);
                }
            })).ToArray());
            sw.Stop();
            Console.WriteLine(pool.GetType().Name + ": " + sw.Elapsed + " " + (GC.CollectionCount(0) - gen0) + " count:" + pool.Count);
            //}
        }
        public void RegisterPool(Type t, IObjectPool pool)
        {
            if (ContainsPoolForType(t))
            {
                Logger.Warning("pool for t:" + t.Name + " exist, now replace it with " + pool.GetType().Name);
            }

            poolDict[t] = pool;
        }