Set Dynamic Memory Allocation Threshold
By default, the code generator uses dynamic memory allocation for variable-size arrays. Dynamic memory allocation optimizes storage requirements for variable-size arrays, but causes slower execution of generated code. To balance memory and performance requirements, you can disable dynamic memory allocation for arrays less than a certain size.
Specify this threshold when you want to:
Disable dynamic memory allocation for smaller arrays. For smaller arrays, static memory allocation can speed up generated code. Static memory allocation can lead to unused storage space. However, you can decide that the unused storage space is not a significant consideration for smaller arrays.
Enable dynamic memory allocation for larger arrays. For larger arrays, when you use dynamic memory allocation, you can significantly reduce storage requirements.
To specify a dynamic memory allocation threshold, dynamic memory allocation must be enabled. To make sure that dynamic memory allocation is enabled, use one of these approaches:
In a code configuration object, make sure that the
EnableDynamicMemoryAllocation
property is set totrue
.In the Code Generation Settings dialog box, make sure that the Enable dynamic memory allocation check box is selected.
If dynamic memory allocation is enabled, set the dynamic memory allocation threshold by using one of these approaches:
In a code configuration object, specify a value for the
DynamicMemoryAllocationThreshold
property.In the Code Generation Settings dialog box, specify a value for the Dynamic memory allocation threshold parameter.
The dynamic memory allocation threshold is measured in bytes. Based on information from the target hardware settings, the code generation estimates the size of the array that the configured threshold can accommodate. This estimate excludes possible C compiler optimizations, such as putting variables in registers.