Specifications

representation of memory showing unused or overlapping regions. You start the BSP Editor from
the Nios II Command Shell. For details about using the BSP Editor, refer to the editor’s tool tips.
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.
For more information about manipulating BSP settings, refer to the “HAL BSP Settings” chapter.
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.
For more information about selecting stack and heap placement, and setting up stack checking, refer to
the "Nios II Software Build Tools" chapter.
For more information about how to control BSP settings, refer to the “HAL BSP Settings” chapter.
Related Information
HAL BSP Settings on page 6-1
Nios II Software Build Tools Reference on page 15-1
Nios II Embedded Software Projects on page 4-4
Global Pointer Register
The global pointer register enables fast access to global data structures in Nios II programs. The Nios II
compiler implements the global pointer, and determines which data structures to access with it. You do
not need to do anything unless you want to change the default compiler behavior.
The global pointer register can access a single contiguous region of 64 KB. To avoid overflowing this
region, the compiler only uses the global pointer with small global data structures. A data structure is
considered “small” if its size is less than or equal to a specified threshold. By default, this threshold is 8
bytes.
The small data structures are allocated to the small global data sections, .sdata, .sdata2, .sbss,
and .sbss2. The small global data sections are subsections of the .rwdata and .bss sections.
NII5V2
2015.05.14
Placement of the Heap and Stack
6-39
Developing Programs Using the Hardware Abstraction Layer
Altera Corporation
Send Feedback