Effacer les filtres
Effacer les filtres

What are some tips for writing efficient C/C++ code for S-Functions?

2 vues (au cours des 30 derniers jours)
MIchael
MIchael le 27 Mai 2011
Can anyone give advices on what I should consider, if I want to write an efficient code in C/C++ for S-Functions?
For example, I am wondering if it is better to read values from Look-Up tables in Simulink, instead of calculating it in the C/C++ code and especially using (standard C) trigonometric functions?
Should I generally avoid standard C math-functions (e.g. a*a instead of pow(a, 2.0))?
Any other points that might be crucial to optimize C/C++ codes?
I think it would be useful to know of such points, if there are any.
Looking forward to any hints.

Réponse acceptée

Kaustubha Govind
Kaustubha Govind le 1 Juin 2011
Regarding Lookup Tables vs. S-Functions, it really depends on your application. Lookup Tables may be faster than (complex) computations, but may increase ROM usage in generated code (assuming you use Simulink Coder to generate embedded C/C++ code from your model). So you need to make a trade-off.
As for more general C/C++ optimizations, I second Jan's suggestion for a C/C++ forum. An S-function is in essence a shared library, so all generic C/C++ language rules apply.

Plus de réponses (2)

Jan
Jan le 27 Mai 2011
It depends on the compiler, the size of the data, the number of calls, the representation of the data (DOUBLEs, Integers, processing of contiguous memory blocks which fit in the processor cache), etc.
A C/C++ forum is a better location for this question.

MIchael
MIchael le 2 Juin 2011
Ok. Thank you both for your answers.
I thought there might be some functunuality in Simulink that I could take advantage of (e.g. avoiding using standard C/C++ math library), so I asked here.
But you are right about a C/C++ forum.

Catégories

En savoir plus sur Simulink Coder dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by