Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

How to calculate min stack size

Options
  • 06-02-2006 2:13pm
    #1
    Closed Accounts Posts: 296 ✭✭


    Hi
    I'm looking for some ways to determine the min stack size i need for my C program. What is the easiest way to calculate how big the stack will grow during runtime?


Comments

  • Registered Users Posts: 441 ✭✭robfitz


    On linux you can use ulimit to set the maximum stack size for a subprocess, the -s value is the size in kilobytes.
    $ ulimit -s 16
    $ java
    # Crash

    You can repeat the commands increasing the -s value until you program doesn't crash anymore.

    Unless your developing for an embedded system you shouldn't have to worrry about the stack size. The problem is mostly likely with your code, you should change your code not to declare large structures on the stack, or not use recursion.


  • Closed Accounts Posts: 296 ✭✭PDelux


    Thanks robfitz, that's a good idea, I can try that.

    It is actually an embedded system I'm working on(USB device) so I need to squeeze every last byte of RAM out of it.


Advertisement