f



mxDestroyArray on a RHS parameter?

Is it legal within a MEX function to call mxDestroyArray on something that's a right hand side parameter input?

If, for example, in a MATLAB script, I call a mexfunc():

bar = mexfunc(foo);

and that mexfunc calls mxDestroyArray on prhs[0], is that equivalent to the calling MATLAB script having done a:

clearvars foo

and expected to run without error?

Thanks!
0
Brandon
12/21/2016 10:18:03 PM
comp.soft-sys.matlab 211266 articles. 17 followers. lunamoonmoon (258) is leader. Post Follow

2 Replies
167 Views

Similar Articles

[PageSpeed] 26

"Brandon Zeidler" wrote in message <o3ev2r$kqb$1@newscl01ah.mathworks.com>...
> Is it legal within a MEX function to call mxDestroyArray on something that's a right hand side parameter input?

No it is not legal. Never Destroy something that is not created by you.

> 
> If, for example, in a MATLAB script, I call a mexfunc():
> 
> bar = mexfunc(foo);
> 
> and that mexfunc calls mxDestroyArray on prhs[0], is that equivalent to the calling MATLAB script having done a:
> 
> clearvars foo

No.

> 
> and expected to run without error?
> 

I will not bet on that. It might crash, I won't try t figure it out.
0
Bruno
12/21/2016 11:01:03 PM
"Bruno Luong" wrote in message <o3f1jf$qab$1@newscl01ah.mathworks.com>...
> "Brandon Zeidler" wrote in message <o3ev2r$kqb$1@newscl01ah.mathworks.com>...
> > Is it legal within a MEX function to call mxDestroyArray on something that's a right hand side parameter input?
> 
> No it is not legal. Never Destroy something that is not created by you.
> 
> > 
> > If, for example, in a MATLAB script, I call a mexfunc():
> > 
> > bar = mexfunc(foo);
> > 
> > and that mexfunc calls mxDestroyArray on prhs[0], is that equivalent to the calling MATLAB script having done a:
> > 
> > clearvars foo
> 
> No.
> 
> > 
> > and expected to run without error?
> > 
> 
> I will not bet on that. It might crash, I won't try t figure it out.


"... It might crash ..."

It WILL almost certainly crash, because MATLAB will try to access invalid memory when it accesses that variable in the calling routine (i.e., MATLAB still thinks that it is a valid variable in the calling routine).  Even if the only thing you did after the mex routine call was to attempt to clear the variable, that will very likely crash MATLAB.  Take Bruno's advice and never do this.

James Tursa
0
James
12/21/2016 11:15:03 PM
Reply: