In C++/mex file, will the changes in memory in C be automatically reflected in Matlab

1 Ansicht (letzte 30 Tage)
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 Kommentar
Adam
Adam am 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?

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Write C Functions Callable from MATLAB (MEX Files) finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by