Defining more than three mwArray gives error
3 次查看(过去 30 天)
显示 更早的评论
Dear Matlab users,
Can you declare and define more than three mwArray in a standalone cpp file that calls the Matlab function in a c++ shared lib (generated by Matlab compiler mcc)? Just try four mwArray:
int N; N=1000;
mwArray in1(N,1,mxDOUBLE_CLASS, mxREAL);
mwArray in2(N,1,mxDOUBLE_CLASS, mxREAL);
mwArray in3(N,1,mxDOUBLE_CLASS, mxREAL);
mwArray in4(3,1,mxINT32_CLASS, mxREAL);
No need to even call the Matlab function after this. I get Matlab runtime crash errors, which goes away if I restrict to only 3 mwArray (any three above).
But this does not happen for following:
mwArray out1,out2,out3,out4;
where notice I didn't allocate lengths of the array because they are output arrays returned by the matlab function I call subsequently.
It is interesting how all examples of using Matlab compiler generated c++ shared library in a c++ code have three or less mwArray defined, two for inputs and one for output.
I am running Matlab R2010b on Ubuntu. Compiler version 4.14.
Another important question: How to transfer in and out a matlab "structure" (with numerical array fields), from a c++ code? I can think of writing it to the disk as mat file and then reading it, but any other elegant idea?
Thanks a lot,
Bir
3 个评论
Shaf
2011-2-16
Hi Bir,
The jvm uses SIGSEGV for flow control. The MCR starts up the jvm during mclInitializeComponentInstanceEmbedded() and that's where the SIGSEGV is coming from and it's safe to ignore. I will look at the code you posted and see if I spot anything. There really aren't any limitations on the number of mwArrays you can create other than running out of memory which doesn't seem to be the case.
回答(1 个)
Shaf
2011-2-8
I will answer the structure question first. You can use mwArrays to create and return MATLAB structures. To assign elements to the struct mwArray you can use mwArray::get() followed by an mwArray::set(const mwArray&). Here are the relevant documentation pages:
http://www.mathworks.com/help/toolbox/compiler/mwarraymwsizenum_rowsmwsizenum_colsintnum_fieldsconstcharfieldnames.html
http://www.mathworks.com/help/toolbox/compiler/mwarraymwsizenum_dimsconstmwsizedimsintnum_fieldsconstcharfieldnames.html
http://www.mathworks.com/help/toolbox/compiler/mwarraygetconstcharnamemwsizenum_indices....html
http://www.mathworks.com/help/toolbox/compiler/voidsetconstmwarrayarr.html
http://www.mathworks.com/help/toolbox/compiler/mwarraygetconstcharnamemwsizenum_indicesconstmwindexindex.html
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!