1.11.1 Library heap usage requirements of the ARM C and C++ libraries

Functions such as malloc() and other dynamic memory allocation functions explicitly allocate memory when used. However, some library functions and mechanisms implicitly allocate memory from the heap.

If heap usage requirements are significant to your code development (for example, you might be developing code for an embedded system with a tiny memory footprint), you must be aware of both implicit and explicit heap requirements.

In C standardlib, implicit heap usage occurs as a result of:

  • Calling the library function fopen() and the first time that an I/O operation is applied to the resulting stream.

  • Passing command-line arguments into the main() function.

The size of heap memory allocated for fopen() is 80 bytes for the FILE structure. When the first I/O operation occurs, and not until the operation occurs, an additional default of 512 bytes of heap memory is allocated for a buffer associated with the operation. You can reconfigure the size of this buffer using setvbuf().

When fclose() is called, the default 80 bytes of memory is kept on a freelist for possible re-use. The 512-byte buffer is freed on fclose().

Declaring main() to take arguments requires 256 bytes of implicitly allocated memory from the heap. This memory is never freed because it is required for the duration of main(). In microlib, main() must not be declared to take arguments, so this heap usage requirement only applies to standardlib. In the standardlib context, it only applies if you have a heap.


The memory sizes quoted might change in future releases.

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