| |||
| Home > Embedded Software Development > Tailoring the image memory map to your target hardware > Placing the stack and heap | |||
The scatter-loading mechanism provides a method for specifying
the placement of code and statically allocated data in your image.
The application stack and heap are set up during C library initialization.
You can tailor stack and heap placement by using the specially named ARM_LIB_HEAP, ARM_LIB_STACK, or ARM_LIB_STACKHEAP execution
regions. Alternatively you can re-implement the __user_initial_stackheap() function if
you are not using a scatter-loading description file.
See Specifying stack and heap using the scatter-loading description file in the Linker User Guide for more information.
RealView Compilation Tools provides the following run-time memory models:
The application stack and heap grow
towards each other in the same region of memory. See Figure 3.7. In this
run-time memory model, the heap is checked against the value of
the stack pointer when new heap space is allocated, for example,
when malloc() is called.
Example 3.2. One-region model routine
LOAD_FLASH ...
{
...
ARM_LIB_STACKHEAP 0x20000 EMPTY 0x20000 ; Heap and stack growing towards
{ } ; each other in the same region
...
}
The stack and heap are placed in separate regions of memory.
For example, you might have a small block of fast RAM that you want
to reserve for stack use only. For a two-region model you must import __use_two_region_memory.
In this run-time memory model, the heap is checked against the heap limit when new heap space is allocated.
Example 3.3. Two-region model routine
LOAD_FLASH ...
{
...
ARM_LIB_STACK 0x40000 EMPTY -0x20000 ; Stack region growing down
{ } ;
ARM_LIB_HEAP 0x28000000 EMPTY 0x80000 ; Heap region growing up
{ }
...
}
In both run-time memory models, the stack grows unchecked.
See Tailoring the runtime memory model in the Libraries and Floating Point Support Guide for more information.