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.

Prototype:

Sample Call from Template:

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():

  1. The number (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.

  1. The number (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.

  1. The array output arguments (mxArray **) themselves, in the order declared for the function.

    In the template, output_arg1 is passed.

  1. The array input arguments (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