Nios® V Processor Software Developer Handbook

ID 743810
Date 2/14/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

6.13.3. Placement of the Heap and Stack

By default, the heap and stack are placed in the same memory partition as the .rwdata section. The stack grows downwards (toward lower addresses) from the end of the section. The heap grows upwards from the last used memory in the .rwdata section. You can control the placement of the heap and stack by manipulating BSP settings.

By default, the HAL performs no stack or heap checking. This makes function calls and memory allocation faster, but it means that malloc() (in C) and new (in C++) are unable to detect heap exhaustion. You can enable run-time stack checking by manipulating BSP settings. With stack checking on, malloc() and new() can detect heap exhaustion.

To specify the heap size limit, set the preprocessor symbol ALT_MAX_HEAP_BYTES to the maximum heap size in decimal. For example, the preprocessor argument -DALT_MAX_HEAP_BYTES=1048576 sets the heap size limit to 0x100000. You can specify this command line option through a BSP setting.

Stack checking has performance costs. If you choose to leave stack checking turned off, you must code your program so as to ensure that it operates within the limits of available heap and stack memory.