Specify the identifier used to declare a DWork vector in code generated from the associated S-function
char_T *ssSetDWorkRTWIdentifier(SimStruct *S, int_T vector, char_T *id)
S
SimStruct representing an S-Function block.
vector
Index of the work vector, where the index is one of
0
, 1
, 2
,
...
ssGetNumDWork(S)-1
.
id
DWork vector Identifier. This must point to persistent memory.
A pointer (char_T *) to the Simulink®
Coder™ identifier entered in id
.
Specifies id
as the identifier used in code generated by the
Simulink
Coder product to declare the DWork vector specified by
vector
. For more information on using DWork vectors, see
How to Use DWork Vectors.
This function must only be called from the mdlInitializeSizes
or mdlSetWorkWidths
functions.
C, C++
See the S-function sfun_rtwdwork.c
used in sfcndemo_sfun_rtwdwork
.
The following portion of the mdlInitializeSizes
method
initializes the DWork vector and all code generation properties associated with
it.
ssSetNumDWork(S, 1); ssSetDWorkWidth(S, 0, 1); ssSetDWorkDataType(S, 0, SS_DOUBLE); /* Identifier; free any old setting and update */ id = ssGetDWorkRTWIdentifier(S, 0); if (id != NULL) { free(id); } id = malloc(80); mxGetString(ID_PARAM(S), id, 80); ssSetDWorkRTWIdentifier(S, 0, id);
The following portion of the mdlTerminate
method frees up the
memory allocated for the identifier to prevent any memory leaks.
char* id; char* tq; /* Identifier; free any old setting and update */ id = ssGetDWorkRTWIdentifier(S, 0); if (id != NULL) { free(id); } ssSetDWorkRTWIdentifier(S, 0, NULL);