Dynamic memory allocation - how is it supported?

it may be best for you to focus on the features of C rather than the enormous # of features added in C++

C, unlike other languages at the time features providing better access to the hardware. pointers that could be defined to memory addresses (unlike in pascal) provided access to hardware registers.

it also supported dynamic memory allocation using malloc()

my understanding is that the heap is the region of memory between the stack and variables. if the stack expands downward, variables and dynamic variables are allocated from the bottom

this can be quite a bit of RAM on a PC, even an early Apple II, is there is only 2kbytes on an AVR 328p

we takes things like printf() for granted, but they aren't actually defined by the language, printf() is part of a library. String is as well, in C++, but somewhat differently because it is part of the std:: namespace (?).

so since things like printf() which isn't supported on Arduino and String are not part of the language, it's fair to say the Arduino IDE uses standard GNU C++ compiler, but doesn't support all the typical libraries.

it appears that someone implement the String class for Arduino outside the std name space but more like it is implemented in Java (i.e. "string") rather than in c++ (i.e. "string").

most Arduino programs can be compiled with appropriate definitions for things like digitalWrite(), millis(),

hopefully others can provide a more precise explanation

1 Like