mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2025-01-12 08:50:31 +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 <cfloat>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
#include <vector>
|
||||||
#include "jkqtcommon/jkqtcommon_imexport.h"
|
#include "jkqtcommon/jkqtcommon_imexport.h"
|
||||||
#include "jkqtcommon/jkqtpmathtools.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;
|
const T* dbl=dbl_in;
|
||||||
T* dbllog=nullptr;
|
QVector<T> dbllog;
|
||||||
if (logScale) {
|
if (logScale) {
|
||||||
double logB=log10(logBase);
|
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));
|
//memcpy(dbl, dbl_in, width*height*sizeof(T));
|
||||||
for (int i=0; i<width*height; i++) {
|
for (int i=0; i<width*height; i++) {
|
||||||
dbllog[i]=log10(dbl_in[i])/logB;
|
dbllog[i]=log10(dbl_in[i])/logB;
|
||||||
}
|
}
|
||||||
min=log10(min)/logB;
|
min=log10(min)/logB;
|
||||||
max=log10(max)/logB;
|
max=log10(max)/logB;
|
||||||
dbl=dbllog;
|
dbl=dbllog.data();
|
||||||
}
|
}
|
||||||
double delta=max-min;
|
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()));
|
jkmpError(jkqtp_format("')' or ',' expected, but '%s' found", currenttokentostring().c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( CurrentToken != RBRACKET ) jkmpError(jkqtp_format("')' expected, but '%s' found", currenttokentostring().c_str()));;
|
if ( CurrentToken != RBRACKET ) jkmpError(jkqtp_format("')' expected, but '%s' found", currenttokentostring().c_str()));;
|
||||||
JKQTPMathParser::jkmpNode** p=nullptr;
|
JKQTPMathParser::jkmpNode** p=nullptr;
|
||||||
if (num>0) {
|
if (num>0) {
|
||||||
p=static_cast<JKQTPMathParser::jkmpNode**>(malloc(sizeof(JKQTPMathParser::jkmpNode*) * num));
|
p=static_cast<JKQTPMathParser::jkmpNode**>(malloc(sizeof(JKQTPMathParser::jkmpNode*) * num));
|
||||||
for (int i=0; i<num; i++) {
|
for (int i=0; i<num; i++) {
|
||||||
p[i]=params[i];
|
p[i]=params[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res=new jkmpFunctionNode(varname, p, num, this, nullptr);
|
res=new jkmpFunctionNode(varname, p, num, this, nullptr);
|
||||||
free(params);
|
free(params);
|
||||||
getToken();
|
getToken();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
res=new jkmpVariableNode(varname, this, nullptr);
|
res=new jkmpVariableNode(varname, this, nullptr);
|
||||||
|
@ -367,15 +367,14 @@ int JKQTPColumnOverlayImageEnhanced::getImageColumn() const
|
|||||||
void JKQTPColumnOverlayImageEnhanced::draw(JKQTPEnhancedPainter &painter) {
|
void JKQTPColumnOverlayImageEnhanced::draw(JKQTPEnhancedPainter &painter) {
|
||||||
const double* d=parent->getDatastore()->getColumnPointer(imageColumn,0);
|
const double* d=parent->getDatastore()->getColumnPointer(imageColumn,0);
|
||||||
size_t imgSize=parent->getDatastore()->getRows(imageColumn);
|
size_t imgSize=parent->getDatastore()->getRows(imageColumn);
|
||||||
bool* locData=static_cast<bool*>(malloc(imgSize*sizeof(bool)));
|
QVector<bool> locData(imgSize,false);
|
||||||
this->data=locData;
|
this->data=locData.data();
|
||||||
this->Ny= static_cast<int>(imgSize/this->Nx);
|
this->Ny= static_cast<int>(imgSize/this->Nx);
|
||||||
for (size_t i=0; i<imgSize; i++) {
|
for (size_t i=0; i<imgSize; i++) {
|
||||||
locData[i]=(d[i]!=0.0);
|
locData[i]=(d[i]!=0.0);
|
||||||
}
|
}
|
||||||
JKQTPOverlayImageEnhanced::draw(painter);
|
JKQTPOverlayImageEnhanced::draw(painter);
|
||||||
free(locData);
|
this->data=nullptr;
|
||||||
data=nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JKQTPColumnOverlayImageEnhanced::usesColumn(int c) const
|
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];
|
JKQTPColumn old=columns[old_column];
|
||||||
size_t rows=old.getRows();
|
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);
|
double* dd=old.getPointer(0);
|
||||||
size_t j=0;
|
size_t j=0;
|
||||||
for (size_t i=start; i<rows; i+=stride) {
|
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];
|
//qDebug()<<old_column<<name<<": "<<j<<i<<d[j];
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
size_t n=addCopiedColumn(d, j, name);
|
size_t n=addCopiedColumn(d.data(), j, name);
|
||||||
free(d);
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user