calloc function arduino UNO....is there enough memory?

Hi everyone i dont know what i’m missing. My board is .http://arduino.cc/en/Main/arduinoBoardUno I need to use a global matrix and size is known at runtime.

int * matrix_state;
int H ,W;
void setup(){
if (condition){
H =32;
W = 16;
}else if(condition1){
H =100;
W = 24;
}else if....
  matrix_state = (int*) calloc(W * H ,sizeof(int));
  for (int y = 0 ;y < H;y++){
    for (int x = 0; x < W;x++){
       Serial.println(matrix_state[y*W + x]);
      }
  }

}

calloc should be to initialize to 0 but if you check the output that doesn’t happen.

output → atached file

i tried this

matrix_state = (int*) calloc(W * H ,sizeof(int));
  
  for (int y = 0 ;y < H;y++){
    for (int x = 0; x < W;x++){
       matrix_state[y*W + x] = 0;
       Serial.println(matrix_state[y*W + x]);
      }
  }

Now matrix_state is a zero’s array but it appears a infinite loop (check the other file).

I think there is not enough memory to allocate matrix_state of a dinamyc way (using calloc) and if i define marix_state[16][32] everything works fine. Another reason why i think that …if H < 25 and W < 16 and i use calloc works fine too.

anyone can tell me something about this issue??
(sorry for my english)

right on the page you linked it says the uno has 2K or RAM.

100242 = 4800 bytes.

thanks yes you are right ,i was wrong i thought in 32 k of RAM :sleeping:. i had to read this http://arduino.cc/en/Tutorial/Memory before post my issue.

its time to buy an arduino Mega 2560.

Or a Bobuino with 16K SRAM.