Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/21/10 18:34:03 (15 years ago)
Author:
gkronber
Message:

Quick fix for #986 (Deserialization of datasets allocates a lot of memory causing OutOfMemoryExceptions)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.DataAnalysis/3.2/Dataset.cs

    r2375 r3468  
    156156    }
    157157
    158     public void SetValue(int i, int j, double v) {
    159       if (v != samples[columns * i + j]) {
    160         samples[columns * i + j] = v;
     158    public void SetValue(int row, int column, double newValue) {
     159      if (newValue != samples[columns * row + column]) {
     160        samples[columns * row + column] = newValue;
    161161        cachedValuesInvalidated = true;
    162162        if (fireChangeEvents) FireChanged();
     
    440440      }
    441441
    442       string[] tokens = node.InnerText.Split(';');
    443       if (tokens.Length != rows * columns) throw new FormatException();
     442      var startPoint = 0;
    444443      samples = new double[rows * columns];
    445444      for (int row = 0; row < rows; row++) {
    446445        for (int column = 0; column < columns; column++) {
    447           if (double.TryParse(tokens[row * columns + column], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out samples[row * columns + column]) == false) {
    448             throw new FormatException("Can't parse " + tokens[row * columns + column] + " as double value.");
     446          if (startPoint >= node.InnerText.Length) throw new FormatException("Not enough elements parsed.");
     447          int endPoint = node.InnerText.IndexOf(';', startPoint);
     448          if (endPoint < 0)
     449            endPoint = node.InnerText.Length;
     450          var curToken = node.InnerText.Substring(startPoint, endPoint - startPoint);
     451          startPoint = endPoint + 1;
     452          if (double.TryParse(curToken, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out samples[row * columns + column]) == false) {
     453            throw new FormatException("Can't parse " + curToken + " as double value.");
    449454          }
    450455        }
    451456      }
     457      if (startPoint < node.InnerText.Length) throw new FormatException("More elements available");
    452458    }
    453459
Note: See TracChangeset for help on using the changeset viewer.