The Mannequin
For instance we’ve a mannequin that operates on its bus argument. The enter and output to this mannequin have the identical bus kind, which for this demonstration consists of parts, b1, a boolean, and d1, a double. In precept, these are two of many parts. Urgent CTRL+B generates code for the mannequin.

The Code
The mannequin modifies the worth of d1 on the bus primarily based on the worth of b1. If we generate code from this mannequin, we get the next step operate:
void A_step(my_bus *arg_in, my_bus *arg_out)
{
real_T tmp;
*arg_out = *arg_in;
if (arg_in->b1) {
tmp = -2.5;
} else {
tmp = 2.5;
}
arg_out->d1 = tmp + arg_in->d1;
}
Discover that the step operate has two arguments, arg_In1 and arg_Out1, and on line 4, the code copies the enter to the ouput. If this have been a big bus, the copy might be fairly costly, so we might prefer to get rid of it.
A Extra Environment friendly Code


To make our argument shared, we make sure that the Configure arguments for Step operate prototype is checked after which set the C Identifier Identify for the enter and output ports to the identical worth. In our case, let’s name it arg_shared. After we re-generate code, we get:
void A_step(my_bus *arg_shared)
{
real_T tmp;
if (arg_shared->b1) {
tmp = -2.5;
} else {
tmp = 2.5;
}
arg_shared->d1 += tmp;
}
Discover that there’s solely a single argument to the step operate and the copy is elimiated, which ends up in rather more environment friendly code.
Now It is Your Flip
How are you avoiding undesirable copies in your generated code? What sorts of enhancements to generated code effectivity would you discover useful?