Info

This question is closed. Reopen it to edit or answer.

How MATLAB mex files access MATLAB instances?

1 view (last 30 days)
Mehrdad
Mehrdad on 30 Dec 2015
Closed: MATLAB Answer Bot on 20 Aug 2021
This is the entry point for every mex file:
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]);
In fact mex files are windows dll files with mexFunction as the main function.
My question is when the mex function is called, how it can access matlab instance specific data from inside the mex. As an example, consider 'mexPutVariable' function. It's job is 'copy an array from inside MEX-function into the specified workspace (outside mex)'. But how it knows where is 'workspace'. No parameter has passed to mex (like a pointer), containing matlab instance data (caller). mex files know only nlhs, plhs, nrhs, prhs and none of them can help mex files to excavate matlab instance specific data(caller function information).

Answers (1)

Walter Roberson
Walter Roberson on 30 Dec 2015
Clearly those passed-in values are not the only special values that MATLAB knows about. MATLAB maintains a calling stack structure of some kind -- it needs such a structure to handle debugging and error messages. It would be simple for mexPutVariable to internally access MATLAB's calling stack structure by its internal name.

Tags

Products

Community Treasure Hunt

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

Start Hunting!