why doesn't global variables space size isn't affected by changing arrays' size?

Why changing a global array's size or type doesn't change the reported "global variables use" reading in the IDE?
If I change the size of a "int data[600];" global declaration or a declare it as byte I get the same reported space use.

You'll have to show the code you're talking about. If you declare that array but don't use it then it may be optimized away.

Here's the relevant part of it:

const int dsize=1000;
int data[dsize];

    
void setup() {
  for (int i=0;i<dsize;i++) {data[i]=1;}

Actually 1000 ints should already be too much but I get the same free SRAM size as with dsize=1.

Your array is assigned but never used. Probably got optimized out by the compiler.

1 Like

Try adding this

 Serial.println(data[0]);

after the for loop

1 Like

UKHeliBob:
Try adding this

 Serial.println(data[0]);

after the for loop

This works. Could you explain me why it's necessary for a correct memory usage estimation?

Garfielder:
This works. Could you explain me why it's necessary for a correct memory usage estimation?

The estimation was correct. Your code didn't include anything requiring the array to be stored in memory. So, it wasn't.

Just because I didn't use the array anywhere?
Well, also this is enough to count the array size in the memory allocation-

int ab=data[3];

or

for (int i=1;i<dsize;i++) {data[i]=data[i-1];}

although I never use elsewhere data[4] or ab itself.
This is a very limited type of optimization.
Thanks. I hope I am getting this right.

Garfielder:
Just because I didn't use the array anywhere?

Why should the compiler allocate memory to hold data that's never used?

I don't understand the rest of your question -- if it is a question?

Well, also this is enough to count the array size in the memory allocation-

int ab=data[3];

or

for (int i=1;i<dsize;i++) {data[i]=data[i-1];}

although I never use elsewhere data[4] or ab itself.
This is a very limited type of optimization.
Thanks. I hope I am getting this right.

So when the compiler checks a variable for being used it looks for reading its value, or any value from it in case it's an array?