Mex-file bugs calling a working C++ code

1 view (last 30 days)
ben
ben on 10 Jun 2013
Hi, i've got a really weird problem. I have a C++ code which is working perfectly well when i'm testing it with some inputs.
When I call exactly the same instructions in a mex function, without Matlab inputs, just calling the same code Matlab doesn't stop computing (infinite loop ?).
What is the difference between calling a code in a mex function, or in a classic main.cpp file ?
I really don't get what happens.
Thanks.
  2 Comments
Jonathan Sullivan
Jonathan Sullivan on 10 Jun 2013
Post your code any maybe we can help.
ben
ben on 10 Jun 2013
Edited: ben on 10 Jun 2013
My code looks like that
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
vector<double> sk1(256, 0);
vector<vector<double>> keyPMF;
for (int i(0) ; i < 16 ; i++)
keyPMF.push_back(sk1);
for (int i(0) ; i < 16 ; i++)
for (int j(0) ; j < 256 ; j++)
file >> keyPMF[i][j];
double poste(2.66091e-35);
RankKey rankEstimation(keyPMF, poste);
rankEstimation.mergeDistribution(16);
auto estimation = rankEstimation(5);
}
where I read some doubles in "file".
The call which doesn't work in the mexFunction is rankEstimation(5). If I run this code without the mexFunction in a main.cpp, it works. In a mexFunction and called by matlab it doesn't work.
I use GMP library to emulatate large intergers in my functions (i'm on 32 bits win XP) and also use some uint64_t integers.
Thanks if you see something.

Sign in to comment.

Answers (2)

Jan
Jan on 10 Jun 2013
MEX-code is code. Code contains bugs. Bugs are known to let programs crash or loop infinitely.

ben
ben on 11 Jun 2013
Are the recursive calls or the heap different using a mexFunction ?

Categories

Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!