mex "out of memory" problem

I'm hoping someone can help me with a problem I'm having with some mex code.
I am using a matlab toolbox and it has some mex function. When I call these c++ function, it crashes and matlab reports that it is "Out of Memory". I really need to fix this problem

2 commentaires

Walter Roberson
Walter Roberson le 17 Sep 2013
Does it crash immediately? Does it crash after it has run a bit on the first call? Does it crash on one of the following calls? Is it possible that you have a memory leak in your C++ code ?
Jagvaral
Jagvaral le 17 Sep 2013
Modifié(e) : Jagvaral le 18 Sep 2013
Thank you for your reply. Actually, the data is very small. I don't have that many variables. The error(OUT OF MEMORY) is occurring when the mxCreateCellArray is called.
dims[0] = nCliques; dims[1] = nCliques; plhs[1] = mxCreateCellArray(2, dims);
So, in order to fix the problem I have changed some variable types from int to mwSize as follows:
mwSize dimsA[2];
mwSize *dims = dimsA;
mwSize ndim = 2;
After I made this change in the code, the function mxCreateCellArray worked fine then I received the returned variable such as clpot, and tried to open clpot.T but Matlab immediately crashed saying that "MATLAB has encountered an internal problem and needs to close". clpot.T matrix :
K>> clpot{1}
ans =
domain: [3 4]
T: [4x1 double]
sizes: [4 1]

Connectez-vous pour commenter.

 Réponse acceptée

Jan
Jan le 17 Sep 2013

0 votes

Please read your question again. Then take the time to check, if it is possible in theory, that anybody can post a useful answer.
Afterwards show us the code, or debug your code to find the problem. Notice that Out-Of-Memory can mean, that installing more memory could potentially solve the problem.
Posting the complete error message is a good idea, when you want others to understand the problem. Perhaps there is any information about the location of the problem? A smart C++ function should catch such errors and show more details to allow to understand the reasons.
Contact the author and tell him the problem.

2 commentaires

Jagvaral
Jagvaral le 17 Sep 2013
Modifié(e) : Jagvaral le 17 Sep 2013
Thank you for your reply. Sorry My english isn't that great. It was actually c mex code. I am not familiar with it. I attached the link here. Please take a look at it. I think the problem occurs when the mxCreateCellArray function is called.
dims[0] = nCliques; dims[1] = nCliques; plhs[1] = mxCreateCellArray(2, dims);
This piece of code is where the error is occurring. error message is saying that Matlab is "Out of memory. Type HELP MEMORY for your options."
Jan
Jan le 17 Sep 2013
Modifié(e) : Jan le 17 Sep 2013
You found one serious problem already, which is related to using int instead of mwSize. But there could be many more similar bugs.
Such problems occur frequently when C-function developed for 32 bits are moved to 64 bit. The required adjustments are not trivial, so I suggest to ask the author. If I'd be very bold, I'd simply replace the "int" by "mwSize". But it is not predictable if the program causes any harm to your computer afterwards. It is not surprising that the code let Matlab crash some times later.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB Compiler dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by