Ignore:
Timestamp:
04/10/17 00:27:31 (3 years ago)
Author:
pkimmesw
Message:

#2665 LexicaseSelector, Performance improvements, UI Fixes, Debugger only shows used stacks, fixed Debugger stepping, Added vector expressions, ERCOptions,

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Pool/ManagedPoolProvider.cs

    r14777 r14834  
    55  using System.Collections.Concurrent;
    66  using System.IO;
    7   using System.Linq;
     7  using System.Reflection;
    88  using System.Runtime.Serialization.Formatters.Binary;
    99
     
    1818    private byte[] dummyPartition;
    1919
     20    private static readonly FieldInfo InternalListArrayProperty = typeof(List<T[]>).GetField(
     21      "_items",
     22      BindingFlags.NonPublic | BindingFlags.Instance);
     23
    2024    private readonly Func<T> factory;
    2125
     
    2933      this.factory = factory;
    3034
    31       managedPools = new ObjectPool<IManagedPool<T>>(() => new ManagedPool<T>(this), MaxParitionCount);
     35      managedPools = new ObjectPool<IManagedPool<T>>(() => new ManagedPool(this));
    3236    }
    3337    public int InstanceCount { get { return partitions.Count * PartitionSize; } }
     
    4650    }
    4751
    48     public void ReleasePartitions(params T[][] partition) {
    49       if (partitions.Count <= MaxParitionCount && partition.Length > 0)
    50         partitions.PushRange(partition);
     52    public void ReleasePartitions(List<T[]> releasedPartitions) {
     53      if (partitions.Count < MaxParitionCount)
     54        partitions.PushRange((T[][])InternalListArrayProperty.GetValue(releasedPartitions), 0, releasedPartitions.Count);
    5155    }
    5256
     
    7175    }
    7276
    73     private class ManagedPool<T> : IManagedPool<T> where T : class, IPooledObject {
     77    private class ManagedPool : IManagedPool<T> {
    7478      private readonly ManagedPoolProvider<T> provider;
    75       private readonly IList<T[]> partitions = new List<T[]>();
     79      private readonly List<T[]> partitions = new List<T[]>();
    7680      private T[] currentPartition;
    7781      private int entryIndex;
     
    8286      }
    8387
    84       public T Get(bool reset = true) {
     88      public T Get(bool resetEntry = true) {
    8589        if (entryIndex == provider.PartitionSize) {
    8690          currentPartition = provider.GetPartition();
     
    9094
    9195        var entry = currentPartition[entryIndex++];
    92 
    93         if (reset) entry.Reset();
    94 
     96        if (resetEntry) entry.Reset();
    9597        return entry;
    9698      }
    9799
    98100      public void Dispose() {
    99         provider.ReleasePartitions(partitions.ToArray());
    100         partitions.Clear();
    101         entryIndex = provider.PartitionSize;
     101        if (partitions.Count > 0) {
     102          provider.ReleasePartitions(partitions);
     103          partitions.Clear();
     104          currentPartition = null;
     105          entryIndex = provider.PartitionSize;
     106        }
     107
    102108        provider.managedPools.Free(this);
    103109      }
Note: See TracChangeset for help on using the changeset viewer.