1000 booleans?

If I create a 1000 item boolean array, my sketch will not run, even though I have 12000 bytes free, aren't booleans only 1 byte a piece? I can run the program fine with 750 booleans. Any ideas?

Thanks

Any ideas?

Yea, your "booleans" are variables. Variables are stored in SRAM so they can change value while your program runs. Program statements don't change, they are stored in FLASH memory. 168 chip has 16k of FLASH and 1K of SRAM, 328 chip doubles both those values.

AVR chip has 'Harvard' computer architecture, that means it uses separate program and data memories, unlike Von neumann architecture (like your PC) where program and data reside in same memory.

Make sense?

Lefty

Arggg. That makes TONS of sense, thanks so much. Is there any way I can get around that? I have a 328, but I'm using it in another project. Can I store variables like that in EEPROM? Thanks

Sorry I don't have any useful info, but I'm curious, what are you using these 1000 booleans for?

I'm not sure how your program is going to operate, but it seems like there would be an easier way. (I could be totally wrong, I'm just so lost on what you'd use 1000 of em for:D)

Slightly more work but you could use an array of characters - index operator to pick a byte, bitwise operator to pick a bit. That way for each byte consumed you're getting 8 bits to set.

The character thing seems like a good idea. I'm using this to record input from an IR remote and play them back later.

here are some functions that I find useful for this kind of thing:

const int maxBits = 1024;  // the number of bits to store (make this evenly divisible by 8)

unsigned char bitData[maxBits / 8];  // uses 128 bytes to store up to 1024 bits

// stores the given bitValue using an index ranging from 0 to 1023
void writeBitArray( int bitIndex, boolean bitValue)
{
   int arrayIndex = bitIndex / 8;
   bitWrite(bitData[arrayIndex], bitIndex % 8, bitValue);
}

// returns the bitValue stored at the given index 
boolean readBitArray(int bitIndex)
{
   int arrayIndex = bitIndex / 8;
   return  bitRead(bitData[arrayIndex], bitIndex % 8 );
}

useage:
writeBitArray(i, bit); // save bit in location given by i
readBitArray(i); // return the bit value at location i

Ha ha! Thanks, that's a very useful piece of code right there. I will definitely use that.

i would like to point to this:

(just for completeness)...

-arne

The character thing seems like a good idea. I'm using this to record input from an IR remote and play them back later.

i would like to point to this:
PROGMEM - Arduino Reference
(just for completeness)...

-arne

You can change the stuff store in the PROGMEM at runtime. Cool tell me how so i can do it.

ohoh
i wasnt aware that u want to write to that array...
i dont know how to write to the flash memory (but it must be possible somehow)... writing to flash memory might significantly reduce the life time of the flash memory (but i'm not sure)...

sorry... :-[

-arne

Have a look at the atmel application notes AVR101 and AVR105

--> writing large amounts of data to flash is faster than writing them to EEprom

--> writing flash is more tricky than writing EEprom

--> there are algorithms for "wear leveling" the application notes describe a very practical one.

Hi Udo,

As it says in AVR105, Flash can only be reprogrammed from the Boot section of memory and so modifying flash at runtime means modifying the Boot code. Are you aware of anyone that has successfully done this with the Arduino boot code?

if it is possible i would love to know how. it would make life so much easier for me.

You'd have to write a custom bootloader, and it's already pretty tight up there.

What are you making that needs 1000 booleans?

why not add a SD card interface and just write the info to a file that you open and close? then you would only be limited on the size of the sd card.

why not add a SD card interface

No need for an SD card, as posted earlier in the thread only 128 bytes of RAM are needed to store the values of 1024 bits.

Perhaps if the OP is still around he could satisfy our curiosity and say what it is he is making.