Search code examples
clinuxmatlabmexundocumented-behavior

Linux (GLNXA64) using mxCreateUninitNumericMatrix R2013b


In one MEX file, I created an output matrix with the command (working fine):

plhs[0] = mxCreateNumericMatrix((mwSize)destLen, 1, mxUINT8_CLASS, mxREAL);

For speedup I wanted to use the dynamic memory uninitialized, which lead me to the undocumented command:

plhs[0] = mxCreateUninitNumericMatrix((mwSize)destLen, 1, mxUINT8_CLASS, mxREAL);

working also very fine within Win32 and Win64.

Using exactly the same code within my Linux environment leads to the following warning from compiler:

warning: assignment makes pointer from integer without a cast [enabled by default]

and the code crashes, which show, that the returned integer value is not that one pointing to the correct memory address.

What can I do to use mxCreateUninitNumericMatrix?


Solution

  • Undocumented MEX functions do not have a corresponding prototype in mex.h header file, so you'll have to explicitly write one yourself. In this case it will be:

    EXTERN_C mxArray *mxCreateUninitNumericMatrix(mwSize m, mwSize n, 
        mxClassID classid, mxComplexity flag);
    

    The EXTERN_C macro expands to extern "C" if you are using C++, otherwise to extern in C, that way you get correct linkage.

    In C (not C++), any undeclared functions are assumed to be external functions that return an integer (at least that's the case with GCC compiler I think).