Can I optimize buffer usage in generated code for input and output arguments of a subsystem with Embedded Coder R2024a?

5 views (last 30 days)

I have a large Simulink model that contains numerous subsystems and model references. The way my model works is that it modifies a large struct type (defined as a Simulink Bus) in place as it passes through components of my model. I am using this model to produce production C++ code using Embedded Coder. Given the scale of my model, and the large memory footprint of the struct type, I do not want reusable functions in my code which copies the struct to a new buffer for output. I want the function to optimize its buffer usage by modifying one struct variable in place. 
This would effectively change the function signature for my reusable function from something like:

void exampleFunction(structType *structIn, structType *structOut) { ... }
to something like: 

void exampleFunction(structType *structInAndOut) { ... }
where one argument is modified in place and treated as output. 
I have done this with Model References in my model.
Is this possible for reusable functions of a subsystem? 

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Aug 2025
As of MATLAB R2024b, this is not possible for a subsystem. 
The development team is aware of this limitation and will consider adding this as a feature in a future release or update.
Depending on the model, there are workarounds available that may be applicable. Different types of buffer reuse optimizations are available for Model References and entry point functions, Simulink Signals, and S-Functions. Please refer to the MathWorks documentation linked above to identify if these workflows can be applied to the model in question. 

More Answers (0)

Categories

Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange

Products


Release

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!