Go Down

Topic: Is stack space fixed size or dynamic (Read 521 times) previous topic - next topic

Riva

I use this library to determine the amount of free RAM my project has as I want to define a circular buffer (at compile time) as large as possible.
Question is, does the stack have a fixed & reserved size not included in the free memory calculation or is it's size dynamic, extending into the free memory pool as I call functions etc.
Also does the Serial library allocate all it memory in the begin class or can/will it allocate more memory as needed later.

Graynomad

#1
Mar 28, 2013, 10:31 am Last Edit: Mar 28, 2013, 10:33 am by Graynomad Reason: 1
Quote
or is it's size dynamic, extending into the free memory pool as I call functions etc.

Yes, the stack varies with every function call and allocation of local (automatic) variables in those functions.

Don't know exactly about the Serial lib but I would say it either uses static arrays or mallocs() for them in the .begin() funct. AFAIK the 64-byte buffer is static.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Nick Gammon

The stack and dynamically allocated memory use the same space. One from the top, one from the bottom.

Quote
I want to define a circular buffer (at compile time) as large as possible


Why?

Riva


The stack and dynamically allocated memory use the same space. One from the top, one from the bottom.

Quote
I want to define a circular buffer (at compile time) as large as possible


Why?

For this. I know there is the arduino SUMP project but I'm no fan of Java (security implications) though it's used in Arduino IDE & Processing but not the full console SUMP needs. Also this would be event driven (pin change) instead of time driven so could maybe capture finer detail for longer than time driven.

Graynomad

So by the time you get to the end of setup() all memory allocation should have been done, you determine how much RAM is left, subtract maybe 100 bytes to allow for the stack to grow, then malloc() the rest. That's your buffer.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Go Up