Linux (GLNXA64) using mxCreateUninitNumericMatrix R2013b
Asked Answered
D

2

1

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?

Diplopia answered 11/12, 2013 at 10:11 Comment(1)
Oh, I got some further bad news: Just played around with MATLAB R2014a Pre: in libmx.dll and libmex.dll I'm missing many former undocumented functions. Seems that we have to look for other ways.Diplopia
W
2

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).

Wieren answered 11/12, 2013 at 13:36 Comment(0)
F
0

It seems that MathWorks has listened and made both mxCreateUninitNumericMatrix and mxCreateUninitNumericArray documented in R2015a. They are declared in matrix.h as follows:

/*
 * Create an uninitialized numeric matrix.
 * The resulting array must be freed with mxDestroyArray.
 */
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C mxArray *mxCreateUninitNumericMatrix(size_t m, 
    size_t n, mxClassID classid, mxComplexity flag);

/*
 * Create an uninitialized numeric array.
 * The resulting array must be freed with mxDestroyArray.
 */
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C mxArray *mxCreateUninitNumericArray (size_t ndim, 
   size_t *dims, mxClassID classid, mxComplexity flag);

The macro LIBMMWMATRIX_PUBLISHED_API_EXTERN_C evaluates to extern or extern C (for MEX files), depending on whether the including source is C or C++.

The official documentation for mxCreateUninitNumericMatrix states:

Call mxCreateUninitNumericMatrix to create a 2-D mxArray in which all data elements have the numeric data type specified by classid. Data elements are not initialized.

mxCreateUninitNumericMatrix allocates dynamic memory to store the created mxArray. Call mxDestroyArray to deallocate the memory.

Documentation for mxCreateUninitNumericArray is similar.

Forehead answered 11/12, 2014 at 0:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.