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

1 vue (au cours des 30 derniers jours)
Yizhi
Yizhi le 6 Août 2014
Commenté : Adam le 7 Août 2014
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 commentaire
Adam
Adam le 7 Août 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?

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by