Shop OBEX P1 Docs P2 Docs Learn Events
Stack size for main using C code: — Parallax Forums

Stack size for main using C code:

Q1. What is the stack size for main?
Q2. How can a program change the stack size for main?
Q3. Is there a utility app for determining stack usage for all active cogs?

Comments

  • 1. The primary stack starts at the end of memory and grows downward toward the end of the program. If you use malloc or calloc it will allocate memory located directly above the end of the program, which reduces the amount of memory available to the primary stack.

    2. The primary stack size cannot be increased. It can be decreased by using malloc or calloc.

    3. Stack usage can be checked by first prefilling the stack with a known value, and then later check for the value starting from the lowest address. This is fairly straightforward to do for the additional cogs. For the initial cog you must account for malloc'ed space, and take care not to overwrite current stack data when prefilling.
  • Dave Hein, thanks.
Sign In or Register to comment.