Is stack space fixed size or dynamic

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.

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

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

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.

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

The project (an Arduino logic analyzer) sounds exciting. I agree with Graynomad that you could basically malloc as much memory as you can, less a hundred or so bytes for the stack (used when you call functions).

However 2000 or so bytes won't capture many data points, especially if you are recording changes and need to save the time along with each change (say, 4 bytes each change).

You can get external SPI-based RAM chips, that could give you a fair bit more.

Or another approach might be a CPLD (logic array) which might be able to simultaneously capture changes and write them to external RAM.

I already have a hardware logic analyser but wanted to do a simple 1 (or maybe 2) channel software only version so peoples on here wanting help decoding signals could maybe be instructed to download and run the analyser sketch and then post the results.
As most stuff to decode comes in small packets I'm hoping an event driven approach of only logging data when something changes instead of every x micro/milli seconds will allow me to capture and serial send at least 425+ changes without buffer overflow.

The stack starts at the top of memory and will grow as-needed without anything to stop it. If it overruns the heap (which starts at the bottom of memory, right after static data, and grows upward), bad things will happen, but there won't be any indication that this has happened.