C Math Library Reference | ![]() ![]() |
Restore the input variables to the memory context at the time of the function call
C Prototype
void mlfRestorePreviousContext(int nout, int nin, ...);
Arguments
int nout
S
pecifies the number of array (mxArray **
) output arguments passed to the current function. Specify 0 if there are no output arguments or no array output arguments.
mxArray *
) input arguments. Specify 0 if there are no input arguments or no array input arguments.
optional mxArray** arguments
mxArray**
output arguments that were passed to the current function.
optional mxArray* arguments
mxArray*
input arguments that were passed to the current function.
You do not need to terminate the list with NULL
; the function detects the end of the argument list from the values of nout
and nin
.
For more information on array input and output arguments, see the "Calling Conventions" section of the MATLAB C Math Library User's Guide.
Description
mlfRestorePreviousContext()
, along with mlfEnterNewContext()
, mlfReturnValue()
, and mlfAssign()
, implement automated memory management in the MATLAB C Math Library. Each function in the library includes calls to these functions. The functions that you write can also use automated memory management by calling these functions.
mlfRestorePreviousContext()
restores the state of the array input arguments to their state at the time of the function call.
mlfRestorePreviousContext()
then performs an important deletion: it deletes any temporary variables that were passed to the current function. This behavior allows you to nest function calls as arguments to functions that use automated memory management. You do not need to worry about deleting the array returned from nested function.
mlfRestorePreviousContext()
is paired with the function mlfEnterNewContext()
. A call to mlfRestorePreviousContext()
is typically the last line of code immediately preceding the return from a function. A matching call to mlfEnterNewContext()
begins the function.
mlfRestorePreviousContext()
also recognizes when the current function was called from a function that does not use automated memory management. In that environment, it does not delete any array input argument that is passed to it.
Example
For a function defined as follows,
mxArray *ArrayMemory(mxArray **z_out, mxArray *x_in, mxArray *y_in)
use the following call to mlfRestorePreviousContext()
at the end of your function prior to the return statement.
mlfRestorerPreviousContext(1, 2, z_out, x_in, y_in);
Use the following call in your main()
routine.
mlfRestorePreviousContext(0, 0);
See Also
mlfEnterNewContext
, mlfReturnValue
, mlfAssign
![]() | mlfPrintMatrix | mlfReturnValue | ![]() |