Two dimensional array in progrm memory

I have a two dimensional array size [6][n] I want to store in program memory. Having read the tutorial on string arrays it would seem that I have to declare an array and then create a table pointing into that array.

However, if I declare an array that is a power of two (in this case 8 by n) I could access it without the lookup table. I assume I need two bytes per table pointer so would I be right in thinking that the following is as memory efficient as using the method described in the tutorial and a bit easer to recover the information?

Therefore the code would look like this:-

prog_uchar table[8][7] PROGMEM = {
52, 57, 62, 67, 71, 76, 0, 0, // last two bytes are just dummy data
52, 57, 62, 67, 71, 76, 0, 0,
52, 57, 62, 67, 71, 76, 0, 0,
52, 57, 62, 67, 71, 76, 0, 0,
52, 57, 62, 67, 71, 76, 0, 0,
52, 57, 62, 67, 71, 76, 0, 0,
52, 57, 62, 67, 71, 76, 0, 0
};

// to recover a row
for(i=0;i<6;i++){
recover*=pgm_read_byte_near(table + i + (0x08 << row));*

  • }*
    Or am I better off using the technique shown in the tutorial?

You should be able to do things like:

            n = pgm_read_word_near(&mydata[row][col]);

And the compiler will do the address arithmetic for you (address arithmetic doesn't care if the address will eventually be in program memory or in ram. Really.) (perhaps the tutorial could use some work...)

This was discussed a bit previously here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1209549912 and I posted a full sketch demonstrating that letting the compiler do the array arithmetic does indeed work.

Thanks that looks like just the thing. :)