1.11.5 Avoiding the heap and heap-using library functions supplied by ARM

If you are developing embedded systems that have limited RAM or that provide their own heap management (for example, an operating system), you might require a system that does not define a heap area.

To avoid using the heap you can either:

  • Re-implement the functions in your own application.

  • Write the application so that it does not call any heap-using function.

You can reference the __use_no_heap or __use_no_heap_region symbols in your code to guarantee that no heap-using functions are linked in from the ARM library. You are only required to import these symbols once in your application, for example, using either:

  • IMPORT __use_no_heap from assembly language.

  • #pragma import(__use_no_heap) from C.

If you include a heap-using function and also reference __use_no_heap or __use_no_heap_region, the linker reports an error. For example, the following sample code results in the linker error shown:

#include <stdio.h>
#include <stdlib.h>
#pragma import(__use_no_heap)

void main()
{ 
    char *p = malloc(256);
    ...
}
Error: L6915E: Library reports error: __use_no_heap was requested, but malloc was referenced

To find out which objects are using the heap, link with --verbose --list=out.txt, search the output for the relevant symbol (in this case malloc), and find out what object referenced it.

__use_no_heap guards against the use of malloc(), realloc(), free(), and any function that uses those functions. For example, calloc() and other stdio functions.

__use_no_heap_region has the same properties as __use_no_heap, but in addition, guards against other things that use the heap memory region. For example, if you declare main() as a function taking arguments, the heap region is used for collecting argc and argv.

Non-ConfidentialPDF file icon PDF versionARM DUI0475M
Copyright © 2010-2016 ARM Limited or its affiliates. All rights reserved.