Using the C Math Library | ![]() ![]() |
Restoring the Previous Context
Each function that you write must close with a call to mlfRestorePreviousContext()
. Place the call just before the return
statement for your function.
The call operates on the output and input array arguments passed to your function. It ensures that the memory allocated for those arrays is restored to its state at the time of the function call.
Note
You can't return from your function before calling mlfRestorePreviousContext() , and you can call mlfRestorePreviousContext() only once in your function.
|
void mlfRestorePreviousContext(int nout, int nin, ...);
mlfRestorePreviousContext(1,2,output_arg1, input_arg1, input_arg2);
Arguments to mlfRestorePreviousContext( )
mlfRestorePreviousContext()
takes the number of output arguments, the number of input arguments, and a variable-length list of the actual output and input arguments to the function. You do not need to terminate the list of arguments with a NULL
argument.
Pass the same arguments to mlfRestorePreviousContext()
as you passed to mlfEnterNewContext()
:
int nout
) of array output arguments declared by your function. Specify 0 if there are no array output arguments declared (in the same way the main()
template function does).
The template function declares one output argument.
int nin
) of array input arguments declared by your function. Specify 0 if there are no array output arguments declared (in the same way the main()
template function does).
The template function declares two input arguments.
mxArray **
) themselves, in the order declared for the function.
In the template, output_arg1
is passed.
mxArray *
) themselves, in the order declared for the function.
In the template, input_arg1
and input_arg2
are passed.
What Happens to the Array Arguments?
mlfRestorePreviousContext()
restores the state of the input arrays to their state at the time of the function call:
mlfRestorePreviousContext()
then performs an important action: it deletes any input array arguments that are temporary.
Purpose of mlfRestorePreviousContext( )
This is the key step that allows a call to another function to be embedded as an input argument to your function. Your function deletes the temporary arrays passed to it, ensuring proper deletion of the memory for temporary arrays.
![]() | Deleting Bound Arrays | Returning an Array | ![]() |