MATLAB Application Program Interface | Search  Help Desk |
mexMakeArrayPersistent | Examples See Also |
Make an mxArray
persist after the MEX-file completes
#include "mex.h" void mexMakeArrayPersistent(mxArray *array_ptr);array_ptr
mxArray
created by an mxCreate
routine.
By default, mxArrays
allocated by mxCreate
routines are not persistent. MATLAB's memory management facility automatically frees nonpersistent mxArrays
when the MEX-file finishes.
Calling mexMakeArrayPersistent
marks an mxArray
as persistent. MATLAB does not automatically free persistent mxArrays
when the MEX-file finishes. In other words, the mxArray
persists through multiple invocations of the MEX-file.
If you do tag an mxArray
as persistent, make sure that the MEX-file does not accidentally recreate the same array each time the MEX-file gets called. That is, make sure that the mxArray
gets created the first time the MEX-file is called. Then, make sure that the mxArray
does not get created again on subsequent calls to the MEX-file.
mxArray
; the MEX-file is responsible for calling mxDestroyArray
to deallocate the heap space.
mexmakearraypersistent.c
in the mex
subdirectory of the examples
directory.
mexAtExit
, mexLock
, mexMakeMemoryPersistent
, and the mxCreate
functions.