Search code examples
cstackmingw

Checking available stack size in C


I'm using MinGW with GCC 3.4.5 (mingw-special vista r3).

My C application uses a lot of stack so I was wondering is there any way I can tell programatically how much stack is remaining so I can cleanly handle the situation if I find that I'm about to run out.

If not what other ways would you work around the problem of potentially running out of stack space?

I've no idea what size of stack I'll start with so would need to identify that programatically also.


Solution

  • Raymond Chen (The Old New Thing) has a good answer to this sort of question:

    If you have to ask, you're probably doing something wrong.

    Here's some Win32 details on stack allocation: MSDN.

    If you think you might be limited by stack space, you will almost certainly be limited by available virtual memory, in which case, you will need to find a different solution.

    What exactly are you trying to do?