- To return an input a copy must be made with mxDuplicateArray.
- MATLAB will delete the object when there are no longer any references to it in MATLAB.
- A null pointer should convert to an empty double array but test this if you depend on it.
C function returning an mxArray pointer
12 次查看(过去 30 天)
显示 更早的评论
Hello!
I am trying to interface our software to Matlab using the functionality to call external, shared libraries from Matlab using loadlibrary and calllib.
My question is:
If I have a C function returning a mxArray pointer: mxArray* myCFunction(mxArray* args);
Will then Matlab be responsible for deleting the object? What If the function returns a null pointer or the input arguments, is this forbidden, e.g.: mxArray* myCFunction(mxArray* args){ return args; }
or
mxArray* myCFunction(mxArray* args){ return 0; }
Best, Joel
0 个评论
采纳的回答
Philip Borghesani
2011-9-1
The rules are the same as for outputs returned via plhs in a mex file.
In short:
2 个评论
Marleen
2025-7-23
Hello, this is outdated information as of matlab 2025a. My DLL functions return mxArray*. On error state it used to return NULL. On matlab side, a calllib call would just throw error as if no output argument is there. So it doesn't even convert to an empty double array. My fix was to change the error handling to use mexErrMsgIdAndTxt, which works wonderfully.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 C Shared Library Integration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!