The Code Generator performs optimization of data allocated for timeouts. Data allocated for a timeout is reused for another timeout if these timeouts trigger transitions outgoing from exclusive states.
Note: Use the menu selections Options->Settings->Optimization ->Reuse Timeout Variable to set that optimization.
● The optimization reuses the same Timeout/Delay variable for other timeouts/delays.To reduce the number of data allocations for the timeout operation, the algorithm has been changed. The description of the algorithm uses the following terms:
● Source state of a timeout— The source state of the transition that the timeout is on, or the state in which its static reaction contains the timeout.
● Clutch a timeout— Add the clutched timeout to the list of timeouts for the timeout that represents the data allocation. Tagging the clutched timeout as NOT requires data allocation. In the clutched timeout, the Code Generator keeps a reference to the timeout that represents its data allocation.
● Parent— State 1 (S1) is a parent of state 2 (S2) if S1 is an ancestor of S2.The algorithm merges data allocation for two timeouts if their sources are mutually exclusive. The steps of the algorithm are as follows:
2. For each timeout in the list (in no particular order), look through the other timeouts for a candidate to be clutched to it.
●
●
The source state and every timeout in the list are not parents of the source state of the tested timeout, or of any of the source states of the timeouts in the list.
●
The source state of the tested timeouts and the source state of every timeout in its list are not parents of the source state, or the source state of any timeout in the list.
●
If all four conditions are satisfied, the tested timeout is clutched. The following code sample represents the algorithm:
CLUTCH TIMEOUT (T1) TO TIMEOUT (TM).Statechart ImplementationAfter the algorithm has finished, each timeout is marked with one of the following tags:
●