mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2025-01-12 00:40:32 +08:00
using automatic memory management instead of local malloc()/free() pairs
This commit is contained in:
parent
3357ca4240
commit
fbbc814331
@ -28,6 +28,7 @@
|
||||
#include <cfloat>
|
||||
#include <stdint.h>
|
||||
#include <QColor>
|
||||
#include <vector>
|
||||
#include "jkqtcommon/jkqtcommon_imexport.h"
|
||||
#include "jkqtcommon/jkqtpmathtools.h"
|
||||
|
||||
@ -654,17 +655,17 @@ inline void JKQTPImagePlot_array2RGBimage(const T* dbl_in, int width, int height
|
||||
|
||||
|
||||
const T* dbl=dbl_in;
|
||||
T* dbllog=nullptr;
|
||||
QVector<T> dbllog;
|
||||
if (logScale) {
|
||||
double logB=log10(logBase);
|
||||
dbllog=static_cast<T*>(malloc(static_cast<size_t>(width)*static_cast<size_t>(height)*sizeof(T)));
|
||||
dbllog.resize(static_cast<size_t>(width)*static_cast<size_t>(height));
|
||||
//memcpy(dbl, dbl_in, width*height*sizeof(T));
|
||||
for (int i=0; i<width*height; i++) {
|
||||
dbllog[i]=log10(dbl_in[i])/logB;
|
||||
}
|
||||
min=log10(min)/logB;
|
||||
max=log10(max)/logB;
|
||||
dbl=dbllog;
|
||||
dbl=dbllog.data();
|
||||
}
|
||||
double delta=max-min;
|
||||
|
||||
@ -865,8 +866,6 @@ inline void JKQTPImagePlot_array2RGBimage(const T* dbl_in, int width, int height
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (logScale) free(dbllog);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1305,17 +1305,17 @@ JKQTPMathParser::jkmpNode* JKQTPMathParser::primary(bool get){
|
||||
jkmpError(jkqtp_format("')' or ',' expected, but '%s' found", currenttokentostring().c_str()));
|
||||
}
|
||||
|
||||
if ( CurrentToken != RBRACKET ) jkmpError(jkqtp_format("')' expected, but '%s' found", currenttokentostring().c_str()));;
|
||||
JKQTPMathParser::jkmpNode** p=nullptr;
|
||||
if ( CurrentToken != RBRACKET ) jkmpError(jkqtp_format("')' expected, but '%s' found", currenttokentostring().c_str()));;
|
||||
JKQTPMathParser::jkmpNode** p=nullptr;
|
||||
if (num>0) {
|
||||
p=static_cast<JKQTPMathParser::jkmpNode**>(malloc(sizeof(JKQTPMathParser::jkmpNode*) * num));
|
||||
for (int i=0; i<num; i++) {
|
||||
p[i]=params[i];
|
||||
}
|
||||
}
|
||||
res=new jkmpFunctionNode(varname, p, num, this, nullptr);
|
||||
free(params);
|
||||
getToken();
|
||||
res=new jkmpFunctionNode(varname, p, num, this, nullptr);
|
||||
free(params);
|
||||
getToken();
|
||||
|
||||
} else {
|
||||
res=new jkmpVariableNode(varname, this, nullptr);
|
||||
|
@ -367,15 +367,14 @@ int JKQTPColumnOverlayImageEnhanced::getImageColumn() const
|
||||
void JKQTPColumnOverlayImageEnhanced::draw(JKQTPEnhancedPainter &painter) {
|
||||
const double* d=parent->getDatastore()->getColumnPointer(imageColumn,0);
|
||||
size_t imgSize=parent->getDatastore()->getRows(imageColumn);
|
||||
bool* locData=static_cast<bool*>(malloc(imgSize*sizeof(bool)));
|
||||
this->data=locData;
|
||||
QVector<bool> locData(imgSize,false);
|
||||
this->data=locData.data();
|
||||
this->Ny= static_cast<int>(imgSize/this->Nx);
|
||||
for (size_t i=0; i<imgSize; i++) {
|
||||
locData[i]=(d[i]!=0.0);
|
||||
}
|
||||
JKQTPOverlayImageEnhanced::draw(painter);
|
||||
free(locData);
|
||||
data=nullptr;
|
||||
this->data=nullptr;
|
||||
}
|
||||
|
||||
bool JKQTPColumnOverlayImageEnhanced::usesColumn(int c) const
|
||||
|
@ -688,7 +688,7 @@ size_t JKQTPDatastore::copyColumn(size_t old_column, size_t start, size_t stride
|
||||
{
|
||||
JKQTPColumn old=columns[old_column];
|
||||
size_t rows=old.getRows();
|
||||
double* d=static_cast<double*>(malloc(rows*sizeof(double)));
|
||||
QVector<double> d(rows, 0.0);
|
||||
double* dd=old.getPointer(0);
|
||||
size_t j=0;
|
||||
for (size_t i=start; i<rows; i+=stride) {
|
||||
@ -696,8 +696,7 @@ size_t JKQTPDatastore::copyColumn(size_t old_column, size_t start, size_t stride
|
||||
//qDebug()<<old_column<<name<<": "<<j<<i<<d[j];
|
||||
j++;
|
||||
}
|
||||
size_t n=addCopiedColumn(d, j, name);
|
||||
free(d);
|
||||
size_t n=addCopiedColumn(d.data(), j, name);
|
||||
return n;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user