Specifications
CAVR-4
44
Data segments
AVR® IAR C/C++ Compiler
Reference Guide
THE HEAP
The heap contains dynamic data allocated by use of the C function malloc (or one of
its relatives) or the C++ operator
new.
If your application uses dynamic memory allocation, you should be familiar with the
following:
● Linker segment used for the heap, which differs between the DLIB and the CLIB
runtime environment
● Allocating the heap size, which differs depending on which build interface you are
using
● Placing the heap segments in memory.
Heap segments in DLIB
Heaps can be placed in the following memory types:
* The TINY_HEAP segment is only available in the Tiny memory model.
To access a heap in a specific memory, use the appropriate memory attribute as a prefix
to the standard functions malloc, free, calloc, and realloc, for example:
__near_malloc
If you use any of the standard functions without a prefix, the function will be mapped to
the default memory type near.
Each heap will reside in a segment with the name
_HEAP prefixed by a memory attribute.
For information about how to access a heap in a specific memory using C++, see New
and Delete operators, page 114.
Heap segments in CLIB
The memory allocated to the heap is placed in the segment HEAP, which is only included
in the application if dynamic memory allocation is actually used.
Memory type Segment name Memory attribute
Tiny TINY_HEAP
*
__tiny
Near NEAR_HEAP __near
Far FAR_HEAP __far
Huge HUGE_HEAP __huge
Table 12: Heaps, memory types, and segments