Page 1 of 1

Arduino (IDE) not showing correct memory for global variables

Posted: Wed Dec 26, 2018 6:39 am
by wonderfuliot
Hi,

I want to check the memory used by globals and wrote the below test code. However the below code shows no additional memory usage as compared to and empty sketch, why?
And how to find out the memory used by globals?

Thanks and Regards,
WI

Code: Select all

volatile char global_mem[16][40];

void setup() {
  Serial.begin(115200);
  for(uint16_t i=0;i<16;++i){
    Serial.print(global_mem[i][i]);
  }
}

void loop() {
}

Re: Arduino not showing correct memory for globals

Posted: Wed Dec 26, 2018 6:40 am
by wonderfuliot
Below is the output:-
Sketch uses 177840 bytes (13%) of program storage space. Maximum is 1310720 bytes.
Global variables use 14528 bytes (4%) of dynamic memory, leaving 313152 bytes for local variables. Maximum is 327680 bytes.

Re: Arduino (IDE) not showing correct memory for global variables

Posted: Fri Dec 28, 2018 4:06 pm
by wonderfuliot
Can somebody from Espressif pls reply?

Re: Arduino (IDE) not showing correct memory for global variables

Posted: Fri Dec 28, 2018 5:14 pm
by paulvha
I am not from Expressif, but I am not surprised.
Even if you do NOT include anything in a sketch, the compiler always includes a number of variables by default (e.g. from different default .h files). Some of these are needed for house-keeping ( pointers in memory, background task etc etc)

Compile an empty sketch: it will take 13272 global bytes by default.
NOW only include Serial.begin(115200);, the result is 13888 (the compiler now includes variables for serial).
14258 - 13888 = 640 = 16 * 40 (volatile char global_mem[16][40];)

Re: Arduino (IDE) not showing correct memory for global variables

Posted: Tue Jan 01, 2019 10:44 am
by wonderfuliot
paulvha, I think you misunderstood my question. I expect the available global memory to go down once I declare my globals. But it does not happen.
The available memory is same whether I declare globals or not.

Re: Arduino (IDE) not showing correct memory for global variables

Posted: Tue Jan 01, 2019 1:41 pm
by paulvha
I may have misunderstood and maybe still do..
I compiled a empty sketch and your sketch. I do see a difference in memory BUT in percentage it is a wash...

Code: Select all

	        Empty sketch	your sketch	
	        bytes	perc	bytes	perc
program mem	173740	13,26%	177840	13,57%
global  mem	13272	4,05%	14528	4,43%