I would like to know how Arduino allocate memory for pointers in function arguments.
For instance. I have this code that use 192 bytes (Arduino IDE compiler: Global variables use 192 bytes (9%) of dynamic memory).
char alph [] = {'a', 'b', 'c','\0'}; // 4 bytes
int numb [] = {1, 2, 3, 4}; // 8 bytes
float flo [] = {1.1, 2.2, 3.3}; // 12 bytes
void fn(){
Serial.println(alph);
Serial.println(numb[1]);
Serial.println(flo[1]);
}
void setup()
{
Serial.begin(9600);
fn();
}
void loop(){}
The following code is the same of above, but I'm using pointer to variables in arguments, that use 234 bytes (Arduino IDE compiller: Global variables use 234 bytes (11%) of dynamic memory).
char alph [] = {'a', 'b', 'c','\0'}; // 4 bytes
int numb [] = {1, 2, 3, 4}; // 8 bytes
float flo [] = {1.1, 2.2, 3.3}; // 12 bytes
void fn(char * _alph, int * _numb, float * _flo){
Serial.println(_alph);
Serial.println(_numb[1]);
Serial.println(_flo[1]);
}
void setup()
Serial.begin(9600);
fn(alph, numb, flo);
}
void loop(){}
There is a difference of 42 bytes to use three pointers. Why? A char pointer is 1 byte, a int pointer is 2 bytes and a float pointer is 4 byte length. Do the difference must be 7 bytes?