Control Stack Space Usage

This example shows how to set the maximum stack space that the generated code uses. Set the maximum stack usage when:

  • You have limited stack space, for instance, in embedded targets.

  • Your C compiler reports a run-time stack overflow.

The value of the property, StackUsageMax, is measured in bytes. Based on information from the target hardware settings, the software estimates the number of stack variables that a certain value of StackUsageMax can accommodate. This estimate excludes possible C compiler optimizations such as putting variables in registers.

Control Stack Space Usage Using the MATLAB Coder App

  1. To open the Generate dialog box, on the Generate Code page, click the Generate arrow .

  2. Set Build type to Source Code, Static Library, Dynamic Library, or Executable (depending on your requirements).

  3. Click More Settings.

  4. On the Memory tab, set Stack usage max to the value that you want.

Control Stack Space Usage at the Command Line

  1. Create a configuration object for code generation.

    Use coder.config with arguments 'lib','dll', or 'exe' (depending on your requirements). For example:

    cfg = coder.config('lib');
  2. Set the property, StackUsageMax, to the value that you want.


Related Topics