This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

deciding on stack and heep size

Hello

I have a general question. Is there a method to find how much should be the size of stack and heep?
I mean for example for a microcontroller with a 20KByte of SRAM what makes the developer to decide on the size of stack and heep?

Parents
  • The developer understands how much of either they plan on using. If you have no malloc()/free() stuff in your code you aren't going to use any heap. If you plan on allocating 2x 8KB buffers concurrently you'd need at least 16KB.

    For the stack, a) understand the depth of your call tree, ie what subroutines call what other subroutines, and b) how large a local/auto variable space that would need. If you have a routine that has a 256 element uint32_t array defined locally you're going to need at least 1KB of stack to even start doing anything.

    Look at the static analysis output by the linker, and look at and evaluate the amount of stack you currently use in normal operation, where it has run for a while and had heavily loaded interrupt processing.

Reply
  • The developer understands how much of either they plan on using. If you have no malloc()/free() stuff in your code you aren't going to use any heap. If you plan on allocating 2x 8KB buffers concurrently you'd need at least 16KB.

    For the stack, a) understand the depth of your call tree, ie what subroutines call what other subroutines, and b) how large a local/auto variable space that would need. If you have a routine that has a 256 element uint32_t array defined locally you're going to need at least 1KB of stack to even start doing anything.

    Look at the static analysis output by the linker, and look at and evaluate the amount of stack you currently use in normal operation, where it has run for a while and had heavily loaded interrupt processing.

Children
No data