From f7ea9b236e2daa48bfc39bd2c3d516aa6a978081 Mon Sep 17 00:00:00 2001 From: "Justin F. Knotzke" Date: Sat, 17 Jan 2009 19:36:31 +0000 Subject: [PATCH] This changes the power histogram implementation to use the QVector data type instead of dynamically allocating and freeing arrays. No memory leak here, but it's an low hanging fruit type of example of what kind of changes we can do to reduce the amount of explicit dynamic memory management. --jtc --- src/PowerHist.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/PowerHist.cpp b/src/PowerHist.cpp index d7dfb4287..d2cdec06f 100644 --- a/src/PowerHist.cpp +++ b/src/PowerHist.cpp @@ -54,8 +54,8 @@ PowerHist::recalc() if (!array) return; int count = (int) ceil((arrayLength - 1) / binw); - double *smoothWatts = new double[count+1]; - double *smoothTime = new double[count+1]; + QVector smoothWatts(count+1); + QVector smoothTime(count+1); int i; for (i = 0; i < count; ++i) { int low = i * binw; @@ -67,12 +67,10 @@ PowerHist::recalc() } smoothTime[i] = 0.0; smoothWatts[i] = i * binw; - curve->setData(smoothWatts, smoothTime, count+1); + curve->setData(smoothWatts.data(), smoothTime.data(), count+1); setAxisScale(xBottom, 0.0, smoothWatts[count]); setYMax(); replot(); - delete [] smoothWatts; - delete [] smoothTime; } void