简体   繁体   English

加载大量数据时WPF内存不足错误

[英]WPF out of memory error when loading large amount of data

I need to process large amount of data into a single List<ChartData> for my custom control. 我需要为List<ChartData>将大量数据处理到单个List<ChartData>中。 About 3 Million points it works fine after reaching the List Count 80,00,000 It throws the Out of memory error. 达到列表计数80,00,000后,它可以正常工作大约300万个点。它引发内存不足错误。 Is there any count limit for List? 列表有计数限制吗? Yes means shall I use any other Collection rather then the List. 是的,我应该使用其他任何集合而不是列表。

Is there a better technique to load large amounts of data into memory? 是否有更好的技术将大量数据加载到内存中? The proplem is in the following function.If ChartIndexedDataPoint.Count is goes to above 30,00,000 问题是在下面的函数中,如果ChartIndexedDataPoint.Count超过30,00,000

 protected override void CalculateSegments(ChartSeries series, ChartIndexedDataPoint[] points)
    {
        double[] yCoef={0};
        IChartDataPoint startPoint = null;
        IChartDataPoint endPoint = null;
        ChartPoint startControlPoint = null;
        ChartPoint endControlPoint = null;
        if (points.Length >= 2)
        {
            NaturalSpline(points, out yCoef);
            if (series.ShowEmptyPoints == false && series.Area.EnableLazyLoading == true)
            {
                allpoints = new List<IChartDataPoint>();
                if (series.ActualYAxis.IsAutoSetRange == true || series.ActualXAxis.IsAutoSetRange == true)
                {
                    series.Segments.Clear();
                    series.Adornments.Clear();

                    for (int i = 0, count = points.Length; i < count - 1; i++)
                    {
                        startPoint = points[i].DataPoint;
                        endPoint = points[i + 1].DataPoint;
                        GetBezierControlPoints(startPoint, endPoint, yCoef[i], yCoef[i + 1], out startControlPoint, out endControlPoint);
                        allpoints.Add(startPoint);
                        allpoints.Add(startControlPoint);
                        allpoints.Add(endControlPoint);
                        allpoints.Add(endPoint);
                    }
                    series.Segments.Add(new ChartFastSplineSegment(allpoints, points, series)); 
                    return;
                }
                if (series.Segments.Count != 0)
                {
                    ChartFastSplineSegment segment = ((ChartFastSplineSegment)series.Segments[0]);

                    if (segment.Points != null && segment.Points.Count < points.Length)
                    {
                        segment.GetSegmet(points[points.Length - 1].DataPoint, series);
                    }
                    else if (segment.Points == null || segment.Points.Count > points.Length)
                    {                           
                        for (int i = 0, count = points.Length; i < count - 1; i++)
                        {
                            startPoint = points[i].DataPoint;
                            endPoint = points[i + 1].DataPoint;
                            GetBezierControlPoints(startPoint, endPoint, yCoef[i], yCoef[i + 1], out startControlPoint, out endControlPoint);
                            allpoints.Add(startPoint);
                            allpoints.Add(startControlPoint);
                            allpoints.Add(endControlPoint);
                            allpoints.Add(endPoint);
                        }
                        segment.UpdateSegment(allpoints, series);
                        segment.refresh = true;
                    }
                }
                else
                {                        
                    for (int i = 0, count = points.Length; i < count - 1; i++)
                    {
                        startPoint = points[i].DataPoint;
                        endPoint = points[i + 1].DataPoint;
                        GetBezierControlPoints(startPoint, endPoint, yCoef[i], yCoef[i + 1], out startControlPoint, out endControlPoint);
                        allpoints.Add(startPoint);
                        allpoints.Add(startControlPoint);
                        allpoints.Add(endControlPoint);
                        allpoints.Add(endPoint);
                    }
                    series.Segments.Add(new ChartFastSplineSegment(allpoints, points, series)); 
                }
            }
            else if (series.Segments.Count == 0 || series.internaldata_modified || allpoints.Count > points.Length)
            {
                allpoints = new List<IChartDataPoint>();
                series.Segments.Clear();
                series.Adornments.Clear();
                ChartIndexedDataPoint[] pts = points;
                List<ChartIndexedDataPoint> tempPointArray = new List<ChartIndexedDataPoint>();                    
                for (int i = 0; i < pts.Length-1; i++)
                {
                    switch (pts[i].DataPoint.EmptyPoint)
                    {
                        case false:
                            {
                                startPoint = points[i].DataPoint;
                                endPoint = points[i + 1].DataPoint;
                                GetBezierControlPoints(startPoint, endPoint, yCoef[i], yCoef[i + 1], out startControlPoint, out endControlPoint);
                                allpoints.Add(startPoint);
                                allpoints.Add(startControlPoint);
                                allpoints.Add(endControlPoint);
                                allpoints.Add(endPoint);
                                tempPointArray.Add(pts[i]);
                                break;
                            }
                        case true:
                            {
                                if (allpoints.Count > 0)
                                {
                                    if (i < points.Length)
                                    {
                                        startPoint = points[i].DataPoint;
                                        endPoint = points[i + 1].DataPoint;
                                        GetBezierControlPoints(startPoint, endPoint, yCoef[i], yCoef[i + 1], out startControlPoint, out endControlPoint);
                                        allpoints.Add(startPoint);
                                        allpoints.Add(startControlPoint);
                                        allpoints.Add(endControlPoint);
                                        allpoints.Add(endPoint);
                                    }
                                    tempPointArray.Add(points[i]);

                                }
                                break;
                            }
                    }
                }
                if (tempPointArray.Count != 0 && allpoints.Count != 0)
                {
                    series.Segments.Add(new ChartFastSplineSegment(allpoints, tempPointArray.ToArray(), series));
                }
            }
            if (series.Segments.Count > 0)
            {
                List<ChartIndexedDataPoint> tempPointArray = new List<ChartIndexedDataPoint>();
                List<ChartIndexedDataPoint> pts = points.ToList();

                if (!series.Contains_emptypt)
                {
                    int cnt = (allpoints.Count+4)/4;
                    while ((allpoints.Count + 4) / 4 != points.Length && (allpoints.Count + 4) / 4 < points.Length)
                    {
                        startPoint = points[cnt-1].DataPoint;
                        endPoint = points[cnt].DataPoint;
                        GetBezierControlPoints(startPoint, endPoint, yCoef[cnt-1], yCoef[cnt], out startControlPoint, out endControlPoint);
                        allpoints.Add(startPoint);
                        allpoints.Add(startControlPoint);
                        allpoints.Add(endControlPoint);
                        allpoints.Add(endPoint);
                        cnt++;
                    }
                }
                (series.Segments[0] as ChartFastSplineSegment).m_points = allpoints;
                if (series.ActualXAxis.IsAutoSetRange || series.Zoomactionenabled)
                {                        
                    double X_MAX = allpoints.Max(x => x.X);
                    double X_MIN = allpoints.Min(x => x.X);
                    (series.Segments[0] as ChartFastSplineSegment).xRange = new DoubleRange(X_MIN, X_MAX);//xRange + cdpt.X;
                    if (series.ActualXAxis.RangeCalculationMode == RangeCalculationMode.AdjustAcrossChartTypes)
                    {
                        (series.Segments[0] as ChartFastSplineSegment).xRange += (series.Segments[0] as ChartFastSplineSegment).xRange.Start - 0.5;
                        (series.Segments[0] as ChartFastSplineSegment).xRange += (series.Segments[0] as ChartFastSplineSegment).xRange.End + 0.5;
                    }
                    (series.Segments[0] as ChartFastSplineSegment).SetRange(series);

                }
                if (series.ActualYAxis.IsAutoSetRange || series.Zoomactionenabled)
                {                        
                    double Y_MAX = allpoints.Max(y => y.Y);
                    double Y_MIN = allpoints.Min(y => y.Y);

                    (series.Segments[0] as ChartFastSplineSegment).yRange = new DoubleRange(Y_MIN, Y_MAX);//yRange + cdpt.Y;

                    if (series.ActualXAxis.RangeCalculationMode == RangeCalculationMode.AdjustAcrossChartTypes)
                    {
                        (series.Segments[0] as ChartFastSplineSegment).xRange += (series.Segments[0] as ChartFastSplineSegment).xRange.Start - 0.5;
                        (series.Segments[0] as ChartFastSplineSegment).xRange += (series.Segments[0] as ChartFastSplineSegment).xRange.End + 0.5;
                    }

                    (series.Segments[0] as ChartFastSplineSegment).SetRange(series);
                    if (series.Zoomactionenabled)
                    {
                        series.Zoomactionenabled = false;
                    }
                }
            }
        }     
    }

Can your application make use of data virtualization? 您的应用程序可以利用数据虚拟化吗? http://www.codeproject.com/Articles/34405/WPF-Data-Virtualization http://www.codeproject.com/Articles/34405/WPF-Data-Virtualization

Even without memory issues, there's no meaningful way to present all of that information at once without summarizing it in some way. 即使没有内存问题,也没有一种有意义的方式可以立即呈现所有这些信息而不以某种方式进行汇总。 You have more data points than there are pixels in a 1920x1080 screen. 您拥有的数据点多于1920x1080屏幕中的像素。 You need to think of ways to reduce the number of points that make sense for your use case. 您需要考虑减少对用例有意义的点数的方法。

Finally i solved this issue. 终于我解决了这个问题。

allpoints.Add(startPoint);
allpoints.Add(startControlPoint);
allpoints.Add(endControlPoint);
allpoints.Add(endPoint);

allpoints into 4 lists 全部归入4个列表

startPoints<IChartDataPoint>
endControlPointS<IChartDataPoint>
endControlPointS<IChartDataPoint>
endPointS<IChartDataPoint>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在单个app实例中加载大量位图时WPF内存不足异常。有限制吗? - WPF out of memory exception when loading large amount of bitmaps in single instance of app. Is there a limit? 当我在 web api ZD7EFADB19FBE7D23D72FD55 中使用数据读取器读取大量数据时,我退出了 memory - i got out of memory when i am reading large amount of data with datareader in web api C# 试图将大量数据写入文件的内存不足异常 - Out of memory exception trying to write large amount of data to a file 从SQL提取大量数据时WPF中的COM上下文错误转换 - Transition from COM context error in WPF when fetching large amount of data from SQL WPF:MemoryStream占用大量内存 - WPF: MemoryStream Occupying large amount of memory 发送大型数据收集时内存不足 - Out of memory when sending large data collections 将大量数据压缩到 output stream 中,而不首先将所有数据加载到 memory 中 - Zipping a large amount of data into an output stream without loading all the data into memory first in C# 登录后在会话中加载大量数据 - Loading large amount of data in session after logging in 管理内存中大量数据的最佳方法? - Best way to manage a large amount of data in memory? 等待大量数据时,DataTables错误500 - DataTables error 500 when waiting for large amount of data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM