Using the C Math Library | ![]() ![]() |
Using Automated Memory Management
You must follow a set procedure when you write a function that conforms to the rules of automated memory management. The pattern is the same for each function.
NULL
or to valid arrays:
Library functions, including mlfAssign()
, require that output arguments
are initialized to NULL
or to a valid array.
mlfEnterNewContext()
to turn on automated memory management for your function and to change the status of temporary input arrays to bound arrays:
Pair this call with a call to mlfRestorePreviousContext()
at the end of your
function.
mlfAssign()
, rather than the assignment operator (=
), to assign values to arrays.
mxDestroyArray()
:
However, do not destroy the return value from your function.
mlfRestorePreviousContext()
to reset the state for each input array the value it had on entering the function and then to delete any temporary arrays:
Pass the same arguments that you passed to mlfEnterNewContext()
.
mlfReturnValue()
to make the array you are returning temporary and then return the temporary array:
![]() | Avoiding Memory Leaks in Your Functions | Function Template | ![]() |