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
This commit is contained in:
Justin F. Knotzke
2009-01-17 19:36:31 +00:00
parent 7026520ec4
commit f7ea9b236e

View File

@@ -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<double> smoothWatts(count+1);
QVector<double> 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