-3

I am writing an Arduino code with 3 arrays.

Two of those are double and other one is int. Further first two arrays have nearly 420 elements for each. Now I noticed that with more that 89 elements on 3rd array the program stall, and stuck executing. But with 89 or less number of element it runs with out an issue.

What would be the issue?

e1065273
  • 1
  • 1

1 Answers1

0

A Mega has 8 KB of memory.

You are using:

  • double (same as float on an Arduino, see double) , 4 bytes * 420 elements * 2 arrays = 3,360 bytes
  • int (2 bytes) * 89 = 178 bytes

In total this is 3,538 bytes

This is about 50%, so I'm unsure what the 'rest' is. You can take a look at the other related question that may show some answers (like using dynamic memory, memory gaps, or local/stack variables): What are the traditional ways to optimize program memory usage?

Michel Keijzers
  • 13,014
  • 7
  • 41
  • 58