Go Down

Topic: array size limit (Read 394 times) previous topic - next topic

sbennett1298

Hello,

  My UNO sketch uses an array of int to store the state of a data pin I want to poll.
How many samples can I store and does it depend on memory I have used elsewhere?
First I tried this:
int array[1000];
The program compiled but would not run.
I finally realized the code would work if I declared a smaller array.
int array[800];

So currently it works with an array size of 800 but if I use more memory by declaring more variables will that reduce my maximum array size even further?

-steve

el_supremo

The UNO has 2kB of static ram which is where that array and all other global variables and the program stack go. An array of 800 ints is 1600 bytes which should leave you enough but as you add more global variables that will eventually push you over the limit again.
If you are using character strings, for example in Serial.print statements, those are also stored in static ram unless you force them to be stored in flash ram (along with the program code).

Pete

Arrch


So currently it works with an array size of 800 but if I use more memory by declaring more variables will that reduce my maximum array size even further?


Yes.

CrossRoads

Can go to a bigger chip - '1284P has 16K SRAM, biggest of any of the 8-bit AVRs.
I sell these bare boards that you can build up. Thinking of offering as kits, or maybe assembled boards.

http://www.crossroadsfencing.com/BobuinoRev17
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up