Skip to content

Commit 01268aa

Browse files
committed
Using std::vector instead of allocating memory myself
1 parent 801f118 commit 01268aa

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

modules/ximgproc/src/estimated_covariance.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class EstimateCovariance{
8787

8888
void iterateCombinations(Mat inputData,Mat outputData);
8989
void computeOneCombination(int comb_id, Mat inputData , Mat outputData,
90-
Mat outputVector,int* finalMatPosR, int* finalMatPosC);
90+
Mat outputVector,std::vector<int> finalMatPosR, std::vector<int> finalMatPosC);
9191

9292
inline void complexSubtract(std::complex<float>& src, std::complex<float>& dst){dst-=src;}
9393
inline void complexAdd(std::complex<float>& src, std::complex<float>& dst){dst+=src;}
@@ -103,7 +103,8 @@ class EstimateCovariance{
103103
int pc;
104104
int threads;
105105

106-
Combination* combinationsTable;
106+
// Combination* combinationsTable;
107+
std::vector<Combination> combinationsTable;
107108
};
108109

109110

@@ -120,12 +121,12 @@ EstimateCovariance::EstimateCovariance(int pr_, int pc_){
120121
}
121122

122123
EstimateCovariance::~EstimateCovariance(){
123-
delete[] combinationsTable;
124+
124125
}
125126

126127
void EstimateCovariance::initInternalDataStructures(){
127128
int combCount = combinationCount();
128-
combinationsTable = new Combination[combCount];
129+
combinationsTable.resize(combCount);
129130
buildCombinationsTable();
130131
}
131132

@@ -203,26 +204,27 @@ void EstimateCovariance::iterateCombinations(Mat inputData,Mat outputData)
203204
combs=combsPerCPU-1;
204205
startComb=remainder*combsPerCPU+(thread_id-remainder)*(combsPerCPU-1);
205206
}
206-
// stopComb=startComb+combs;
207+
207208
Mat outputVector(pr*pc,1, DataType<std::complex<float> >::type);
208209

209-
int* finalMatPosR = new int[pr*pc];
210-
int* finalMatPosC = new int[pr*pc];
210+
std::vector<int> finalMatPosR(pr*pc,0);
211+
std::vector<int> finalMatPosC(pr*pc,0);
211212

212213
for (idx=0; idx<combs; idx++){
213214
outputVector.setTo(Scalar(0,0));
214-
memset(finalMatPosR,0,pr*pc*sizeof(int));
215-
memset(finalMatPosC,0,pr*pc*sizeof(int));
215+
for (unsigned x=0; x<finalMatPosR.size(); x++)
216+
finalMatPosR[x]=0;
217+
for (unsigned x=0; x<finalMatPosC.size(); x++)
218+
finalMatPosC[x]=0;
216219
computeOneCombination(startComb++, inputData, outputData,
217220
outputVector,finalMatPosR, finalMatPosC);
218221
}
219-
delete[] finalMatPosR;
220-
delete[] finalMatPosC;
222+
221223
}
222224
}
223225

224226
void EstimateCovariance::computeOneCombination(int comb_id,Mat inputData, Mat outputData,
225-
Mat outputVector,int* finalMatPosR, int* finalMatPosC)
227+
Mat outputVector,std::vector<int> finalMatPosR, std::vector<int> finalMatPosC)
226228
{
227229
Combination* comb = &combinationsTable[comb_id];
228230
int type2 = comb->type2;

0 commit comments

Comments
 (0)