ssSetUserData
Specify user data
Syntax
void ssSetUserData(SimStruct *S, void *data)
Arguments
S
SimStruct that represents an S-Function block.
data
User data.
Description
Stores a pointer to the memory location containing the S-function's user data. To
avoid memory leaks, the S-function must free this memory location during the call to
mdlTerminate
.
An S-function containing user data must perform the following steps.
Allocate memory for the user data, using a customized structure to store more complicated data.
Set the
SS_OPTION_CALL_TERMINATE_ON_EXIT
option inmdlInitializeSizes
, to ensure the Simulink® engine always calls themdlTerminate
function.Store the pointer to the memory location in the user data, using a call to
ssSetUserData
.In
mdlTerminate
, usessGetUserData
to retrieve the pointer to the memory location and free the memory.
See Creating Run-Time Parameters from Multiple S-Function Parameters for an example that uses user data in conjunction with run-time parameters.
Note
You cannot access user data from within a Target Language Compiler (TLC) file.
Use DWork vectors instead of user data if you need to write a TLC-file to inline
the S-function during code generation with Simulink
Coder™. For an example using DWork vectors, see sfcndemo_sfun_rtwdwork
.
Languages
C, C++
Examples
See the S-function sfun_runtime4.c
used in sfcndemo_runtime
.
See Also
Version History
Introduced before R2006a