In C++/mex file, will the changes in memory in C be automatically reflected in Matlab
1 view (last 30 days)
Show older comments
Hello, I am kind of new to the mex functions. If I use the mxGetData to get the pointer to the array and I change the value in the memory of that array, do I still need to make a copy of values using some mxfunctions and return it to matlab? Or I need to do nothing and the value in Matlab will automatically change?
In other words, if we pass values to cpp using mxFunctions, do they do a shadow copy or a deep copy?
To make the question clear, here is an example C code:
float * temp_data = (float*) mxGetData(prhs[0]);//at this time, temp_data[0] = 0
temp_data[0] = 1;
If I don't do anything to return the temp_data, will the value in matlab be changed?
Thank you.
1 Comment
Adam
on 7 Aug 2014
I'm afraid I don't know the answer off-hand, though I assume if you already have your mex program setup you could verify one way or the other in a few seconds yourself?
Answers (0)
See Also
Categories
Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!