Specify reusability of the memory allocated to the output port of an S-function
void ssSetOutputPortOptimOpts(SimStruct *S, int_T port, uint_T val)
Use this macro to specify the reusability and scope of the memory allocated to an S-function output port. The reusability indicates whether or not the memory associated with the output port can be overwritten. You must specify that an output port is reusable if the output port connects to a Merge block. The scope indicates whether the model variables are stored locally or globally.
You cannot use ssGetOutputPortSignal or ssGetOutputPortRealSignal anywhere except in the mdlOutputs routine if you have specified that the output ports are reusable.
The Simulink® product only uses the reusability setting during simulation. It disregards the memory scope setting, i.e., local or global, instead treating all S-function ports as global during simulation.
Note: The Simulink Coder™ product uses the memory scope setting you specified when generating code from a model. If your S-function accesses the outputs only in mdlOutputs, the Simulink Coder product attempts to declare local variables for any outputs with a local scope. If your S-function uses the outputs in a way that precludes using a local scope, the generated code uses global variables for the outputs. See S-Functions for Multirate Multitasking Environments for more information.
See the S-function sdotproduct.csdotproduct.c used in sfcndemo_sdotproductsfcndemo_sdotproduct and the S-function sfun_multirate.csfun_multirate.c used in sfcndemo_sfun_multiratesfcndemo_sfun_multirate.