1

How do you get to know the available stack space for your C++ programs on your computer? Is it OS-specific / compiler-specific / IDE-specific, and can you alter it? (to increase / decrease the available memory space)

Note: I am using a GCC/G++ compiler from a Windows 10 OS.

Coder Alpha
  • 157
  • 1
  • 10
  • 1
    It's OS/compiler/IDE specific. It's not part of the C standard. – Jabberwocky Sep 08 '21 at 11:26
  • 1
    It is system specific, it will be totally different for say an arduino then for a high end desktop processor and will vary between operating systems as well (I think solaris even grew stack space dynamically if you where near a page boundary). – Pepijn Kramer Sep 08 '21 at 11:26
  • And no you don't have control over it. The heap exists for a reason ;) – Pepijn Kramer Sep 08 '21 at 11:27
  • Maybe this helps: https://stackoverflow.com/questions/156510/increase-stack-size-on-windows-gcc – Jabberwocky Sep 08 '21 at 11:28
  • 2
    If you feel that you need to do this, the probability that it would be better to change your code is almost indistinguishable from 1. – molbdnilo Sep 08 '21 at 11:30
  • This question make it seem like you're having stack issues, possibly by using too large arrays as local variables. Don't do that, and the solution is not to increase the stack size but to use other means of allocations. – Some programmer dude Sep 08 '21 at 11:30
  • Also for future questions, please ask about the *actual* and *underlying* problem directory instead. Right now this question is too much of an [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). – Some programmer dude Sep 08 '21 at 11:31
  • @PKramer depending on the OS and compiler/linker, the stack size could be set/changed when the binary is built. – t.niese Sep 08 '21 at 11:32
  • Why does this question require an underlying problem in the first place? Its like replying to [this question](https://stackoverflow.com/questions/8454248/making-a-custom-kernel) with "don't, Linux already exists". – Kaihaku Sep 08 '21 at 11:52
  • @t.niese Thanks, never needed that. So I assumed from code ;) – Pepijn Kramer Sep 08 '21 at 11:53

0 Answers0