RAM overflow

Hello, I have a really big sketch with a few arrays like int mynum[300]; and also lots of libraries used. And when I use a method from one of the libraries the arduino resets itself. Is this because there isn't enough space left i the RAM? Thanks

JVPython

One int array with 300 elements uses 600 bytes. Depending on which Arduino you have, you have between 2K and 8K of SRAM where data gets stored. A “few” arrays that size will use up all available memory.

so would that be the reason for the reset?

JVPython

Could be. When you write something into one of those arrays that doesn't fit in the available space, code could be overwritten, which could result in an invalid instruction, which could trigger a reset.

ok thanks ill recheck my code. :slight_smile:

@PaulS: How is code overwritten in a Harvard architecture, just because you run out of RAM?

Groove,

code isn't overwritten, but the stack is messed up and once you have a return address on the stack that points to 0 on the next return statement will create your reset. That's why buffer overflows are such a popular security risk.

Korman

Korman: yes, I know that, I just wondered if PaulS did

Hello,

i wrote a little note about how to find the RAM Overflow:

Arduino Ram Overflow

Neat article. Everyone should read it.

People should also remember that you need to leave some memory for your stack and, if you used new or malloc, the heap.

Embedded systems won't give you an out of memory exception dialogue box so these issues can be REALLY hard to debug.

Because of this it's often bad form to: 1) use new and malloc 2) use recursion

@designer2k2: I don't understand your reference to EEPROM and program memory. Did you mean flash memory?

Hello,

i wrote a little note about how to find the RAM Overflow:

–>Arduino Ram Overflow<–

Really good article!! nice