Is there any limit on stack memory?

前端 未结 6 2039
清酒与你
清酒与你 2020-12-16 20:06

I was going through one of the threads. A program crashed because it had declared an array of 10^6 locally inside a function.

Reason being given was memory allocatio

6条回答
  •  猫巷女王i
    2020-12-16 20:52

    Yes, there is a limit on stack size in most languages. For example, in C/C++, if you have an improperly written recursive function (e.g. incorrect base case), you will overflow the stack. This is because, ignoring tail recursion, each call to a function creates a new stack frame that takes up space on the stack. Do this enough, and you will run out of space.

    Running this C program on Windows (VS2008)...

    void main()
    {
        main();
    }
    

    ...results in a stack overflow:

    Unhandled exception at 0x004113a9 in Stack.exe: 0xC00000FD: Stack overflow.

提交回复
热议问题