Ardunio SRAM Usage when deailing with large arrays

Greeting!
I am currently working on a project and experiencing a weird behavior which i do not understand and googling this is confusing me even further. so i would really appreciate some clarification.

I am make a very large array of 1600 bytes (using Sizeof()) which i assume would be place in SRAM, but when i use the memory() library it shows only 115 bytes being used. Here is the code which i tested it on

#include <MemoryFree.h>

byte database [][4] =  {
{ 0 , 6 , 20 , 20 } ,
{ 0 , 6 , 20 , 20 } ,
{ 0 , 7 , 20 , 20 } ,
{ 0 , 7 , 60 , 48 } ,

................................ Paste Bin for all the rest the forum wont let me  (https://pastebin.com/WRmJckJP)

{ 0 , 7 , 20 , 20 } ,
{ 0 , 7 , 60 , 48 } ,
{ 0 , 7 , 20 , 20 } ,
{ 0 , 7 , 20 , 20 } ,
{ 0 , 7 , 20 , 20 } ,
{ 0 , 7 , 60 , 48 } ,
{ 0 , 7 , 20 , 20 } ,
{ 0 , 7 , 20 , 20 } ,
{ 0 , 7 , 20 , 20 } ,
{ 0 , 7 , 60 , 48 } ,
};

void setup() {
    Serial.begin(9600);
}


void loop() {
    //Serial.println(str);
    Serial.println(sizeof(database));
    Serial.print("freeMemory()=");
    Serial.println(freeMemory());

    delay(1000);
}

I am using a Arduino Leo which has 2.5KB of SRAM. Where is this 1600 Bytes going?

Thanks,

RAM_Usage__Test_.ino (9.26 KB)

You never used the array, so the compiler determined that it was not needed and removed it from the final code.

Thanks for the answer but even when i try to access the array via Serial.print(database[50][10][2]); it works which means the array gets put into memory but even then the memory() function shows the same. Correct me if i am wrong

TheYellowRanger:
Thanks for the answer but even when i try to access the array via Serial.print(database[50][10][2]); it works which means the array gets put into memory but even then the memory() function shows the same. Correct me if i am wrong

The compiler is smart enough to know that you are only using one element of the array and that element is a constant so it just uses the constant and throws away the array.
Perhaps you should write loops to show all of the elements. That's one way to tell the compiler you are using the data.

You will need to access it a bit more, the compiler gets fairly aggressive when optimizing code, it sees a single access of a value that never changes, so just took that single number and printed it.

Add something like this:

  if (millis() == 4000000000ul) {
    for (int i = 0; i < sizeof(database) / sizeof(database[0]); i++) {
      Serial.println(database[i][0]);
    }
  }

That won't actually print anything, unless you leave the arduino running for 40 days or so, but forces the compiler to include the array because it will be used at some point.

Thanks for all the answers its clear now. However if i want to allocate a specific space to be used in the future such as a serial buffer array how would i declare it.

You might declaring it 'volatile'.

Thanks everyone for the help