User`s manual

2 Creating C Language MEX-Files
2-40
Hybrid Arrays
Functions such as mxSetPr, mxSetData, and mxSetCell allow the direct
placement of memory pieces into an
mxArray. mxDestroyArray will destroy
these pieces along with the entire array. Because of this, it is possible to create
an array that cannot be destroyed, i.e., an array on which it is not safe to call
mxDestroyArray. Such an array is called a hybrid array, because it contains
both destroyable and nondestroyable components.
For example, it is not legal to call
mxFree (or the ANSI free() function, for that
matter) on automatic variables. Therefore, in the following code fragment,
pArray is a hybrid array.
mxArray *pArray = mxCreateDoubleMatrix(0, 0, mxREAL);
double data[10];
mxSetPr(pArray, data);
mxSetM(pArray, 1);
mxSetN(pArray, 10);
Another example of a hybrid array is a cell array or structure, one of whose
children is a read-only array (an array with the
const qualifier, such as one of
the inputs to the MEX-file). The array cannot be destroyed because the input
to the MEX-file would also be destroyed.
Because hybrid arrays cannot be destroyed, they cannot be cleaned up by the
automatic mechanism outlined in “Automatic Cleanup of Temporary Arrays”
on page 2-38. As described in that section, the automatic cleanup mechanism
is the only way to destroy temporary arrays in case of a user interrupt.
Therefore, temporary hybrid arrays are illegal and may cause your MEX-file to
crash.
Although persistent hybrid arrays are viable, we recommend avoiding their
use wherever possible.
Using LAPACK and BLAS Functions
LAPACK is a large, multiauthor Fortran subroutine library that MATLAB
uses for numerical linear algebra. BLAS, which stands for Basic Linear
Algebra Subroutines, is used by MATLAB to speed up matrix multiplication
and the LAPACK routines themselves. The functions provided by LAPACK
and BLAS can also be called directly from within your C MEX-files.