当前位置: 首页>>代码示例>>C#>>正文


C# ObjectPool类代码示例

本文整理汇总了C#中ObjectPool的典型用法代码示例。如果您正苦于以下问题:C# ObjectPool类的具体用法?C# ObjectPool怎么用?C# ObjectPool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ObjectPool类属于命名空间,在下文中一共展示了ObjectPool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: New

 public static AsteroidWallpaper New(ObjectPool big, ObjectPool small)
 {
     var instance = CreateInstance<AsteroidWallpaper>();
     instance.big = big;
     instance.small = small;
     return instance;
 }
开发者ID:antfarmar,项目名称:Unity-3D-Asteroids,代码行数:7,代码来源:AsteroidWallpaper.cs

示例2: TestAllocateAndFree

        public void TestAllocateAndFree()
        {
            var pool = new ObjectPool<TestElement>();
            pool.Initialize();

            Assert.IsTrue(pool.UsedListSize == 0 && pool.FreeListSize == 0);

            // allocate some instances
            var e1 = pool.Allocate();
            var e2 = pool.Allocate();

            Assert.IsTrue(pool.UsedListSize == 2 && pool.FreeListSize == 0);
            Assert.IsTrue(e1 != e2);
            Assert.IsTrue(e1.value == 0);

            // free both and then allocate two more again - we should get both back

            pool.Free(e1);
            pool.Free(e2);
            Assert.IsTrue(pool.UsedListSize == 0 && pool.FreeListSize == 2);

            var e3 = pool.Allocate();
            var e4 = pool.Allocate();
            Assert.IsTrue(pool.UsedListSize == 2 && pool.FreeListSize == 0);
            Assert.IsTrue(e3 == e2);
            Assert.IsTrue(e4 == e1);
        }
开发者ID:rzubek,项目名称:UnityGameTools,代码行数:27,代码来源:ObjectPoolTest.cs

示例3: GameBoard

        /// <summary>
        /// Initializes the game board.
        /// </summary>
        /// <param name="width">The width of the board.</param>
        /// <param name="height">The height of the board.</param>
        /// <param name="initialDensity">The initial population density to use to populate the board.</param>
        /// <param name="pool">The pool of Bitmaps to use.</param>
        /// <param name="ruleSet">The rule set.</param>
        public GameBoard(int width, int height, double initialDensity, ObjectPool<Bitmap> pool, string ruleSet)
        {
            // Validate parameters
            if (width < 1) throw new ArgumentOutOfRangeException("width");
            if (height < 1) throw new ArgumentOutOfRangeException("height");
            if (pool == null) throw new ArgumentNullException("pool");
            if (ruleSet == null) throw new ArgumentNullException("pool");
            if (initialDensity < 0 || initialDensity > 1) throw new ArgumentOutOfRangeException("initialDensity");

            // Store parameters
            _pool = pool;
            Width = width;
            Height = height;
            _ruleSet = ruleSet;

            // Create the storage arrays
            _scratch = new Color?[2][,] { new Color?[width, height], new Color?[width, height] };

            // Populate the board randomly based on the provided initial density
            Random rand = new Random();
            for (int i = 0; i < width; i ++)
            {
                for (int j = 0; j < height; j++)
                {
                    _scratch[_currentIndex][i, j] = (rand.NextDouble() < initialDensity) ? Color.FromArgb(rand.Next()) : (Color?)null;
                }
            }
        }
开发者ID:kunalgujar,项目名称:GameOfLife,代码行数:36,代码来源:GameOfLifeLogic.cs

示例4: ReOpenDb

        private void ReOpenDb()
        {
            Db = new TFChunkDb(new TFChunkDbConfig(PathName,
                                                   new VersionedPatternFileNamingStrategy(PathName, "chunk-"),
                                                   10000,
                                                   0,
                                                   WriterCheckpoint,
                                                   ChaserCheckpoint,
                                                   new InMemoryCheckpoint(-1),
                                                   new InMemoryCheckpoint(-1)));

            Db.Open();

            var readers = new ObjectPool<ITransactionFileReader>("Readers", 2, 5, () => new TFChunkReader(Db, Db.Config.WriterCheckpoint));
            TableIndex = new TableIndex(Path.Combine(PathName, "index"),
                                        () => new HashListMemTable(MaxEntriesInMemTable * 2),
                                        () => new TFReaderLease(readers),
                                        MaxEntriesInMemTable);
            ReadIndex = new ReadIndex(new NoopPublisher(),
                                      readers,
                                      TableIndex,
                                      new ByLengthHasher(),
                                      0,
                                      additionalCommitChecks: true,
                                      metastreamMaxCount: MetastreamMaxCount);
            ReadIndex.Init(ChaserCheckpoint.Read());
        }
开发者ID:danieldeb,项目名称:EventStore,代码行数:27,代码来源:TruncateAndReOpenDbScenario.cs

示例5: AddPoolableComponent

 public static Poolable AddPoolableComponent(GameObject newInstance, ObjectPool pool)
 {
     scriptBuiltInstance = true;
     var instance = newInstance.AddComponent<Poolable>();
     instance.pool = pool;
     return instance;
 }
开发者ID:antfarmar,项目名称:Unity-3D-Asteroids,代码行数:7,代码来源:Poolable.cs

示例6: Main

        static void Main(string[] args)
        {
            CancellationTokenSource cts = new CancellationTokenSource();

            // Create an opportunity for the user to cancel.
            Task.Run(() =>
            {
                if (Console.ReadKey().KeyChar == 'c' || Console.ReadKey().KeyChar == 'C')
                    cts.Cancel();
            });

            ObjectPool<TestClass> pool = new ObjectPool<TestClass>(() => new TestClass());

            // Create a high demand for MyClass objects.
            Parallel.For(0, 1000000, (i, loopState) =>
            {

                using(TestClass mc = pool.GetResource())
                {
                    Console.CursorLeft = 0;
                    // This is the bottleneck in our application. All threads in this loop
                    // must serialize their access to the static Console class.
                    Console.WriteLine("{0:####.####}", mc.GetValue(i));
                    // pool.PoolResource(mc); alternative to implementing repool in the dispose method
                }

                if (cts.Token.IsCancellationRequested)
                    loopState.Stop();

            });
            Console.WriteLine("Press the Enter key to exit.");
            Console.ReadLine();
            cts.Dispose();
        }
开发者ID:chivandikwa,项目名称:ObjectPool,代码行数:34,代码来源:Program.cs

示例7: Access

 public Access(string accessFileName)
 {
   var acFile = accessFileName.Replace('\\', '/').Replace("//", "/");
   this.connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}", acFile);
   this.pool = new ObjectPool<OleDbConnection>(() => new OleDbConnection(connectionString));
   this.PageSize = 14;
 }
开发者ID:shengqh,项目名称:RCPA.Core,代码行数:7,代码来源:Access.cs

示例8: Awake

 // Use this for initialization
 public void Awake()
 {
     player = GameObject.FindGameObjectWithTag ("Player");
     playerController = player.GetComponent<PlayerController>();
     gameController = GameObject.Find("GameController").GetComponent<GameController>();
     objectPool = GameObject.Find("Pool").GetComponent<ObjectPool>();
 }
开发者ID:Zeropointstudios,项目名称:Hybrid_Skies,代码行数:8,代码来源:Finder.cs

示例9: Awake

 protected override void Awake()
 {
     base.Awake();
     GameObject gameController = GameObject.FindGameObjectWithTag(Tags.GAMECONTROLLER);
     _gameController = gameController.GetComponent<GameController>();
     _objectPool = gameController.GetComponent<ObjectPool>();
 }
开发者ID:mennolp098,项目名称:Boom-Boom-Boomerang,代码行数:7,代码来源:GoldCoin.cs

示例10: GetObstacle

 ///////////////////////////////////////////////	
 private GameObject GetObstacle(ObjectPool pool)
 {
     GameObject obstacle = pool.getNextObject ();
     var pos = pool.prototype.transform.position;
     obstacle.transform.position = new Vector3 (pos.x, pos.y, pos.z);
     return obstacle;
 }
开发者ID:JulianG,项目名称:MossRunningGame,代码行数:8,代码来源:ObstacleFactory.cs

示例11: CompilationData

 public CompilationData(Compilation comp)
 {
     _semanticModelsMap = new Dictionary<SyntaxTree, SemanticModel>();
     this.SuppressMessageAttributeState = new SuppressMessageAttributeState(comp);
     _declarationAnalysisDataMap = new Dictionary<SyntaxReference, DeclarationAnalysisData>();
     _declarationAnalysisDataPool = new ObjectPool<DeclarationAnalysisData>(() => new DeclarationAnalysisData());
 }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:7,代码来源:AnalyzerDriver.CompilationData.cs

示例12: InitPool

	void InitPool ()
	{
		pool = new ObjectPool<DynamicBrick> (initSize, addSize);
		pool.NewObject = NewDynamicBrick;
		pool.Init ();
		
	}
开发者ID:saoniankeji,项目名称:JumpJump_Pure,代码行数:7,代码来源:BrickManager.cs

示例13: ReOpenDb

        private void ReOpenDb()
        {
            Db = new TFChunkDb(new TFChunkDbConfig(PathName,
                                                   new VersionedPatternFileNamingStrategy(PathName, "chunk-"),
                                                   10000,
                                                   0,
                                                   WriterCheckpoint,
                                                   ChaserCheckpoint,
                                                   new InMemoryCheckpoint(-1),
                                                   new InMemoryCheckpoint(-1)));

            Db.Open();

            var readers = new ObjectPool<ITransactionFileReader>("Readers", 2, 5, () => new TFChunkReader(Db, Db.Config.WriterCheckpoint));
            var lowHasher = new XXHashUnsafe();
            var highHasher = new Murmur3AUnsafe();
            TableIndex = new TableIndex(Path.Combine(PathName, "index"), lowHasher, highHasher,
                                        () => new HashListMemTable(PTableVersions.Index64Bit, MaxEntriesInMemTable * 2),
                                        () => new TFReaderLease(readers),
                                        PTableVersions.Index64Bit,
                                        MaxEntriesInMemTable);
            ReadIndex = new ReadIndex(new NoopPublisher(),
                                      readers,
                                      TableIndex,
                                      0,
                                      additionalCommitChecks: true,
                                      metastreamMaxCount: MetastreamMaxCount,
                                      hashCollisionReadLimit: Opts.HashCollisionReadLimitDefault);
            ReadIndex.Init(ChaserCheckpoint.Read());
        }
开发者ID:SzymonPobiega,项目名称:EventStore,代码行数:30,代码来源:TruncateAndReOpenDbScenario.cs

示例14: InitPool

	void InitPool ()
	{
		m_Pool_Brick = new ObjectPool<Brick> (100, 20);
		m_Pool_Brick.NewObject = NewBrick;
		m_Pool_Brick.Init ();
		
	}
开发者ID:saoniankeji,项目名称:JumpJump_Pure,代码行数:7,代码来源:BlockManager.cs

示例15: LookupResult

 private LookupResult(ObjectPool<LookupResult> pool)
 {
     _pool = pool;
     _kind = LookupResultKind.Empty;
     _symbolList = new ArrayBuilder<Symbol>();
     _error = null;
 }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:7,代码来源:LookupResult.cs


注:本文中的ObjectPool类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。