10.6 Heap Allocation
calloc()
, malloc()
, and
realloc()
. If you do not use any of these functions (directly or
indirectly), then you do not need to allocate a heap.If you do want to use dynamic memory allocation, either directly, by calling one of the memory allocation functions, or indirectly, by using a standard C library function that uses one of these functions, then a heap must be created. A heap is created by specifying its size on the linker command line using the --defsym=_min_heap_size
linker command line option. An example of allocating a heap of 512 bytes using the command line is:
xc32-gcc foo.c -Wl,--defsym=_min_heap_size=512
The linker allocates the heap immediately before the stack. The location and size of the heap are reported in the link map output file and in the Memory-Usage Report, under the heading Dynamic Memory Usage. If the requested size is not available, the linker reports an error.
The heap is now dynamically allocated by the linker. Previous releases used output sections specified in the linker script to allocate the heap.