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

1 次查看(过去 30 天)
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 个评论
Adam
Adam 2014-8-7
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?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Write C Functions Callable from MATLAB (MEX Files) 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by