www.gusucode.com > simulinkcoder 案例源码程序 matlab代码 > simulinkcoder/MemsetFunctionExample.m
%% Optimize Generated Code Using |memset| Function % This example shows how to optimize the generated code by using the |memset| % function to clear the internal storage. % When you select the model configuration parameter *Use memset to initialize % floats and doubles to 0.0*, the |memset| function clears internal storage, % regardless of type, to the integer bit pattern |0| (that is, all bits are % off). % % If your compiler and target CPU both represent floating-point zero with % the integer bit pattern |0|, consider setting this parameter to gain % execution and ROM efficiency. % % *NOTE:* The command-line values are the reverse of the settings values. % 'on' in the command line corresponds to clearing the setting. |'off'| in % the command line corresponds to selecting the setting. % % This optimization: % % * Reduces ROM consumption. % * Improves execution speed. %% Example Model % Consider the model <matlab:rtwdemo_memset>. model = 'rtwdemo_memset'; open_system(model); %% Generate Code % The code generator uses a loop to initialize the |Constant| block values. % % Create a temporary folder (in your system temporary folder) for the % build and inspection process. currentDir = pwd; [~,cgDir] = rtwdemodir(); %% % Build the model. rtwbuild(model) %% % View the generated code without the optimization. These lines of code are % in |rtwdemo_memset.c|. cfile = fullfile(cgDir,'rtwdemo_memset_grt_rtw','rtwdemo_memset.c'); rtwdemodbtype(cfile,'/* Model initialize function */',... '/* Model terminate function */',1,0); %% Enable Optimization % # Open the Configuration Parameters dialog box. % # On the *All Parameters* tab, select % *Use memset to initialize floats and doubles to 0.0*. % % Alternatively, you can use the command-line API to enable the optimization: set_param(model,'InitFltsAndDblsToZero','off'); %% Generate Code with Optimization % The code generator uses the |memset| function to initialize the |Constant| % block values. %% % Build the model. rtwbuild(model) %% % View the generated code with the optimization. These lines of code are % in |rtwdemo_memset.c|. rtwdemodbtype(cfile,'/* Model initialize function */',... '/* Model terminate function */',1,0); %% % Close the model and the code generation report. bdclose(model) rtwdemoclean; cd(currentDir)