Why does code generated using MATLAB Coder call the "emxEnsureCapacity" function even when I have disabled variable sizing?
2 views (last 30 days)
Show older comments
MathWorks Support Team
on 14 Nov 2016
Answered: MathWorks Support Team
on 14 Nov 2016
When I generate code for a MATLAB function using MATLAB Coder, I notice calls to a function "emxEnsureCapacity" in the generated code. I understand that this function is called when working with variable-sized arrays. I have no variable sized arrays in my MATLAB function, and I have also unchecked the 'Enable variable sizing' option in the MATLAB Coder settings. Why, then, are there still calls to the "emxEnsureCapacity" function? I believe this is slowing down the speed of the generated code.
Accepted Answer
MathWorks Support Team
on 9 Jan 2017
In case you are working with fixed size arrays and would like to prevent calls to "emxEnsure Capacity", in the memory settings, please change the 'Dynamic Memory Allocation' option from 'For all variable sized arrays' to 'Never'. This will result in faster run times for the generated code.
Note that there are two different 'Settings' profiles in the MATLAB Coder app - one in the Check for Run Time Issues page (appears as 'Settings'), and one in the Generate Code page (appears as 'more settings') . These represent two entirely different 'Settings' profiles, with the first Settings profile being used for generating the MEX file and checking for runtime issue, while the second one is used to actually generate the code. Therefore, any settings changes made in the 'Check for Run time issues' page, must also be made in the 'Generate Code' page for it to be reflected in the generated code. Hence, be sure to set Dynamic Memory Allocation to 'Never' in both these pages.
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!