Arduino (IDE) not showing correct memory for global variables

wonderfuliot
Posts: 9
Joined: Sun Nov 18, 2018 12:25 pm

Arduino (IDE) not showing correct memory for global variables

Postby wonderfuliot » Wed Dec 26, 2018 6:39 am

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() {
}
Last edited by wonderfuliot on Wed Dec 26, 2018 7:00 am, edited 2 times in total.

wonderfuliot
Posts: 9
Joined: Sun Nov 18, 2018 12:25 pm

Re: Arduino not showing correct memory for globals

Postby wonderfuliot » Wed Dec 26, 2018 6:40 am

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.

wonderfuliot
Posts: 9
Joined: Sun Nov 18, 2018 12:25 pm

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

Postby wonderfuliot » Fri Dec 28, 2018 4:06 pm

Can somebody from Espressif pls reply?

paulvha
Posts: 6
Joined: Thu Dec 27, 2018 2:29 pm

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

Postby paulvha » Fri Dec 28, 2018 5:14 pm

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];)

wonderfuliot
Posts: 9
Joined: Sun Nov 18, 2018 12:25 pm

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

Postby wonderfuliot » Tue Jan 01, 2019 10:44 am

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.

paulvha
Posts: 6
Joined: Thu Dec 27, 2018 2:29 pm

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

Postby paulvha » Tue Jan 01, 2019 1:41 pm

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%

Who is online

Users browsing this forum: No registered users and 47 guests