Using memory efficiently

I'm a little hazy on the memory usage in the Arduino software. I have a number of independent modules that will run in sequence. Since these are pretty independent, in a normal programming environment I'd conserve memory by utilizing the stack as much as possible, e. g. make each module a function with local variables on the stack.

So the question is, does this model work on the Arduino? Is there also a heap?

Thanks, Jim.

For the AVR processor that uses the Harvard architecture, variables and stack are both located in the same SRAM memory so in reality using global variables would decrease SRAM usage I would think.

Lefty

Re: Using memory efficiently Reply #1 - Today at 17:20:43 For the AVR processor that uses the Harvard architecture, variables and stack are both located in the same SRAM memory so in reality using global variables would decrease SRAM usage I would think.

Lefty

I agree. I was just wanted to be sure the stack exists and goes away at the end of a function. If I need 100 bytes of memory in 200 different functions, can I assume I'm going to get them, 100 at a time, like in conventional c environments? Or are they somehow always statically assigned?

Thanks, Jim.

I was just wanted to be sure the stack exists and goes away at the end of a function

Only the current stack frame goes away at the end of the function, not the stack itself.

If I need 100 bytes of memory in 200 different functions, can I assume I'm going to get them

It depends on how the functions are nested. If they're all consecutive, then yes, you'll get them.

It depends on how the functions are nested. If they're all consecutive, then yes, you'll get them.

So it behaves like a conventional C or C++ program. Thanks, that's what I wanted to be sure of.

Jim.

So it behaves like a conventional C or C++ program.

Yes, and that is because it essentially is. :)