Go Down

Topic: what is the 2d array size limit for Arduino (Read 1 time) previous topic - next topic

iamhuzhe

I need to flush out some data that are stored in a constant 2d byte array. Wondering what, if there is a limitation on the size of array I can define in one sketch? How big X can be?

byte data[X][64]={{128, 0, 128, 16, 128, 32, 128, 56, 128, 72, 128, 88, 128, 104, 128,
 120, 136, 0, 136, 24, 136, 40, 136, 48, 136, 64, 136, 80, 136, 104,
 136, 120, 144, 0, 144, 16, 144, 32, 144, 48, 144, 64, 144, 80, 144,
 96, 144, 112, 152, 0, 152, 16, 152, 32, 152, 48, 152, 64, 152, 80,
 128, 0, 128, 0}, {128, 0, 128, 16, 128, 40, 128, 56, 128, 72, 128,
 88, 128, 104, 128, 120, 136, 0, 136, 24, 136, 32, 136, 48, 136, 64,
 136, 80, 136, 104, 136, 112, 144, 0, 144, 16, 144, 32, 144, 48, 144,
  64, 144, 80, 144, 96, 144, 112, 152, 0, 152, 16, 152, 32, 152, 48,
 152, 64, 152, 80, 128, 0, 128, 0}, {128, 0, 128, 16, 128, 40, 128,
 56, 128, 72, 128, 88, 128, 104, 128, 120, 136, 0, 136, 24, 136, 40,
 136, 48, 136, 64, 136, 80, 136, 104, 136, 112, 144, 0, 144, 16, 144,
  32, 144, 48, 144, 64, 144, 80, 144, 96, 144, 112, 152, 0, 152, 16,
 152, 32, 152, 48, 152, 64, 152, 80, 128, 0, 128, 0}, {128, 0, 128,
 16, 128, 40, 128, 56, 128, 64, 128, 88, 128, 104, 128, 120, 136, 0,
 136, 24, 136, 40, 136, 48, 136, 64, 136, 80, 136, 96, 136, 112, 144,
  0, 144, 16, 144, 32, 144, 48, 144, 64, 144, 80, 144, 96, 144, 112,
 152, 0, 152, 16, 152, 32, 152, 48, 152, 64, 152, 80, 128, 0, 128,
 0}};

kg4wsv

Since the ATmega has 1k of RAM, the absolute limit is 1024/64 = 16.

In reality, other things need some RAM, too, so the actual number will be less than 16, but depend on the program.

-j

Cheater

Alternatively if its constant then you could buy a cheap serial EEPROM and chuck it on there.
That'll give you up to a meg of dedicated space for a couple of cents.

iamhuzhe

Thanks for the answers. Now I realized that I was trying to solve the wrong problem  :'(.

I worked on some custom protocol to send data between Arduino and MSP430F2013. It only worked on and off. I spent most of the time tuning the timing, however without realizing that my 2D array exceeds the 1K RAM size limit of Arduino, which is the real problem.

Unfortunately its IDE doesn't warm me that my byte array used up of the RAM (like IAR IDE does).

Fortunately once the problem is identified, I can quickly googled out a solution by storing my byte array in the flash memory.

prog_uchar data[20][64] PROGMEM = ...

... ...
...  = (byte)pgm_read_byte(&data[j]);
... ...

(http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=38003&postdays=0&postorder=asc)
(http://www.arduino.cc/en/Reference/PROGMEM)
(http://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html#g39235a28487ae7790ce5f4c8178c8ed7)

After thought, the Arduino IDE's easiness to use totally makes me unconscious of my dealing with a MCU (where RAM size is a very limited resource). I worked very hard to fit my code into MSP430F2013's 128B RAM. And IAR IDE will warn me if things don't fit. It would be great if Arduino can have that function as well as step-by-step debugging. Am I being too greedy  :P

mellis

Actually, having the IDE tell you how much RAM you're using (or a guess at least) would be really nice.  I'm don't know how to do it, but I'll have to investigate for future versions of the software.

Go Up