Changeset 15189 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data
- Timestamp:
- 07/10/17 21:36:03 (7 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Pool/IPooledObject.cs
r14777 r15189 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Data.Pool { 2 2 public interface IPooledObject { 3 void Init(); 3 4 void Reset(); 4 5 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Pool/ManagedPoolProvider.cs
r15017 r15189 10 10 public interface IManagedPool<T> : IDisposable where T : class, IPooledObject { 11 11 T Get(bool reset = true); 12 void Release(); 12 13 } 13 14 … … 17 18 private readonly BinaryFormatter binaryFormatter = new BinaryFormatter(); 18 19 private byte[] dummyPartition; 20 private static volatile object dummyCreationLockObject = new object(); 19 21 20 22 private static readonly FieldInfo InternalListArrayProperty = typeof(List<T[]>).GetField( … … 37 39 public int InstanceCount { get { return partitions.Count * PartitionSize; } } 38 40 39 private void InitDummyPartition(Func<T> factory) {40 var temp = new T[PartitionSize];41 42 for (var i = 0u; i < PartitionSize; i++) {43 temp[i] = factory();44 }45 46 using (var memoryStream = new MemoryStream()) {47 binaryFormatter.Serialize(memoryStream, temp);48 dummyPartition = memoryStream.ToArray();49 }50 }51 52 41 public void Clear() { 42 dummyPartition = null; 43 managedPools.Clear(); 53 44 partitions.Clear(); 54 45 } … … 65 56 66 57 private T[] CloneDummyPartition() { 67 if (dummyPartition == null) 68 InitDummyPartition(factory); 58 if (dummyPartition == null) { 59 lock (dummyCreationLockObject) { 60 if (dummyPartition == null) { 61 var temp = new T[PartitionSize]; 62 63 for (var i = 0u; i < PartitionSize; i++) { 64 temp[i] = factory(); 65 } 66 67 using (var memoryStream = new MemoryStream()) { 68 binaryFormatter.Serialize(memoryStream, temp); 69 dummyPartition = memoryStream.ToArray(); 70 } 71 } 72 } 73 } 69 74 70 75 using (var memoryStream = new MemoryStream(dummyPartition)) { 71 76 memoryStream.Seek(0, SeekOrigin.Begin); 72 77 73 return (T[])binaryFormatter.Deserialize(memoryStream); 78 var result = (T[])binaryFormatter.Deserialize(memoryStream); 79 80 for (var i = 0; i < result.Length; i++) 81 result[i].Init(); 82 83 return result; 74 84 } 75 85 } … … 102 112 } 103 113 104 public void Dispose() {114 public void Release() { 105 115 if (partitions.Count > 0) { 106 116 provider.ReleasePartitions(partitions); … … 109 119 entryIndex = provider.PartitionSize; 110 120 } 121 } 122 123 public void Dispose() { 124 Release(); 111 125 112 126 provider.managedPools.Free(this); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Pool/ObjectPool.cs
r14777 r15189 6 6 7 7 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Data.Pool { 8 using System.Collections.Generic; 8 9 using System.Threading; 9 10 … … 102 103 } 103 104 } 105 106 public void Clear() { 107 for (int i = 0; i < _items.Length; i++) { 108 _items[i] = default(Element); 109 } 110 } 111 112 public IEnumerable<T> Items 113 { 114 get 115 { 116 var items = _items; 117 for (var i = 0; i < items.Length; i++) { 118 if (items[i].Value != null) { 119 yield return items[i].Value; 120 } 121 } 122 } 123 } 104 124 } 105 125 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Pool/PooledList.cs
r14908 r15189 6 6 [Serializable] 7 7 public class PooledList<T> : List<T>, IPooledObject { 8 public void Reset() { 8 public Guid Id { get; private set; } 9 10 void IPooledObject.Init() { 11 Id = Guid.NewGuid(); 12 } 13 14 void IPooledObject.Reset() { 9 15 Clear(); 10 16 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Pool/PooledObject.cs
r14908 r15189 20 20 } 21 21 22 void IPooledObject.Init() { } 23 22 24 public void Reset() { 23 25 resetor(item); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Tree/TreeExtensions.cs
r15017 r15189 81 81 } 82 82 83 return new PushProgram(expressions.To Array());83 return new PushProgram(expressions.ToList()); 84 84 } 85 85 }
Note: See TracChangeset
for help on using the changeset viewer.