Using the C Math Library    

Enabling Memory Management 

A function that uses automated memory management must begin with a call to mlfEnterNewContext(). Typically, you place the call after the declaration and initialization of local variables. You must call mlfEnterNewContext() before the first call to mlfAssign().

The call to mlfEnterNewContext() signals that MATLAB C Math Library automated memory management is in effect for the function. mlfEnterNewContext() operates on the output and input array arguments passed to your function. It ensures that the memory allocated for those arrays, whether temporary or bound, persists for the duration of the function and will not be destroyed by your function or any function that it calls.

Pass these arguments to mlfEnterNewContext() in the order listed. You do not need to terminate the list of arguments with a NULL argument.

  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 on Main Routine Template).

    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 input arguments declared (in the same way the main() template function does).

    The template function on Function Template 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.

Creating Bound Arrays

mlfEnterNewContext() changes the state of temporary input arrays from temporary to bound, enabling them to persist for the duration of the function. If they are passed as input arguments to other functions, they are passed as bound arrays and not deleted.


 Function Template Assigning Arrays to mxArray* Variables