Skip to Main Content Skip to Search
Product Documentation

ssSetUserData - Specify user data

Syntax

void ssSetUserData(SimStruct *S, void *data)

Arguments

S

SimStruct representing 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.

  1. Allocate memory for the user data, using a customized structure to store more complicated data.

  2. Set the SS_OPTION_CALL_TERMINATE_ON_EXIT option in mdlInitializeSizes, to ensure the Simulink engine always calls the mdlTerminate function.

  3. Store the pointer to the memory location in the user data, using a call to ssSetUserData.

  4. In mdlTerminate, use ssGetUserData 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.

Languages

C, C++

Example

See the S-function sfun_runtime4.c used in sfcndemo_runtime.mdl.

See Also

ssGetUserData

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS