Changeset 14834 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/InterpreterPoolContainer.cs
- Timestamp:
- 04/10/17 00:27:31 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/InterpreterPoolContainer.cs
r14777 r14834 22 22 expressionListPoolProvider = new ManagedPoolProvider<PooledList<Expression>>(partitionSize, () => new PooledList<Expression>(), maxPartitionCount); 23 23 24 InitStatefulExpressionPools( );24 InitStatefulExpressionPools(partitionSize, maxPartitionCount); 25 25 } 26 26 … … 33 33 this.expressionListPoolProvider = expressionListPoolProvider; 34 34 35 InitStatefulExpressionPools( );35 InitStatefulExpressionPools(1024, 2048); 36 36 } 37 37 38 public IManagedPool<PushProgram> PushProgramPool { get; private set; } 39 public IManagedPool<LoopState> LoopStatePool { get; private set; } 40 public IManagedPool<PooledList<Expression>> ExpressionListPool { get; private set; } 38 private IManagedPool<PushProgram> pushProgramPool; 39 public IManagedPool<PushProgram> PushProgramPool 40 { 41 get 42 { 43 if (pushProgramPool == null) pushProgramPool = pushProgramPoolProvider.CreatePool(); 44 return pushProgramPool; 45 } 46 } 41 47 42 private void InitStatefulExpressionPools() { 48 private IManagedPool<LoopState> loopStatePool; 49 public IManagedPool<LoopState> LoopStatePool 50 { 51 get 52 { 53 if (loopStatePool == null) loopStatePool = loopStatePoolProvider.CreatePool(); 54 return loopStatePool; 55 } 56 } 57 58 private IManagedPool<PooledList<Expression>> expressionListPool; 59 public IManagedPool<PooledList<Expression>> ExpressionListPool 60 { 61 get 62 { 63 if (expressionListPool == null) expressionListPool = expressionListPoolProvider.CreatePool(); 64 return expressionListPool; 65 } 66 } 67 68 private void InitStatefulExpressionPools(int partitionSize, int maxPartitionCount) { 43 69 for (var i = 0; i < ExpressionTable.StatefulExpressionTypes.Length; i++) { 44 70 var type = ExpressionTable.StatefulExpressionTypes[i]; 45 71 var name = ExpressionTable.TypeToNameTable[type]; 46 var factory = ExpressionTable.StatefulExpressionFactory[name];47 72 48 statefulExpressionPoolProviders.Add(type, new ManagedPoolProvider<Expression>(1024, factory)); 73 statefulExpressionPoolProviders.Add(type, new ManagedPoolProvider<Expression>( 74 partitionSize, 75 ExpressionTable.StatefulExpressionFactory[name], 76 maxPartitionCount)); 49 77 50 78 statefulExpressionPools.Add(type, null); … … 52 80 } 53 81 54 public IManagedPool<Expression> GetStatefulExpressionPool<T, StateT>() where T : StatefulExpression<StateT> { 55 return statefulExpressionPools[typeof(T)]; 82 public T GetStatefulExpression<T>() where T : Expression { 83 var type = typeof(T); 84 if (statefulExpressionPools[type] == null) 85 statefulExpressionPools[type] = statefulExpressionPoolProviders[type].CreatePool(); 86 87 return (T)statefulExpressionPools[type].Get(); 56 88 } 57 89 58 public T GetStatefulExpression<T>() where T : Expression { 59 return (T)statefulExpressionPools[typeof(T)].Get(); 60 } 90 public void DisposePools() { 91 if (pushProgramPool != null) { 92 pushProgramPool.Dispose(); 93 pushProgramPool = null; 94 } 61 95 62 public void CreatePools() { 63 PushProgramPool = pushProgramPoolProvider.CreatePool(); 64 LoopStatePool = loopStatePoolProvider.CreatePool(); 65 ExpressionListPool = expressionListPoolProvider.CreatePool(); 96 if (loopStatePool != null) { 97 loopStatePool.Dispose(); 98 loopStatePool = null; 99 } 100 101 if (expressionListPool != null) { 102 expressionListPool.Dispose(); 103 expressionListPool = null; 104 } 66 105 67 106 for (var i = 0; i < ExpressionTable.StatefulExpressionTypes.Length; i++) { 68 107 var type = ExpressionTable.StatefulExpressionTypes[i]; 69 statefulExpressionPools[type] = statefulExpressionPoolProviders[type].CreatePool(); 70 } 71 } 108 var pool = statefulExpressionPools[type]; 72 109 73 public void DisposePools() { 74 if (PushProgramPool != null) PushProgramPool.Dispose(); 75 if (LoopStatePool != null) LoopStatePool.Dispose(); 76 if (ExpressionListPool != null) ExpressionListPool.Dispose(); 77 78 for (var i = 0; i < ExpressionTable.StatefulExpressionTypes.Length; i++) { 79 var type = ExpressionTable.StatefulExpressionTypes[i]; 80 if (statefulExpressionPools[type] != null) statefulExpressionPools[type].Dispose(); 110 if (pool != null) { 111 pool.Dispose(); 112 statefulExpressionPools[type] = null; 113 } 81 114 } 82 115 }
Note: See TracChangeset
for help on using the changeset viewer.