Search code examples
memory-managementdata-structuresstacklanguage-agnosticstack-overflow

Is overflowing a stack part of its implementation or that's just something that is restricted by the memory/RAM constraints of the OS?


When you hear stack overflow, does that mean that the stack had initially 1mb capacity and then you added more items...increased it size, so the stack was resized to 2mb...and then on on and until it was resized to 10mb...however it was never able to resized to 11mb because the stack has a maximum capacity size?

Or is it that there is no such restriction at the stack level, rather the restriction comes from the app/program. And that restriction can fluctuate based on a number of reasons. e.g. if your iPhone is low on memory then it will only allow 10mb of stack, however if it has 1Gb of free memory then the app will be able to use all that space, hence the maximum stack capacity would be close to 1Gb?

My question is unlike the linked question. It's not about an app's call-stack. Rather it's purely about who will take down an overflowing stack? And show that be part of the stack's implementation or what?


Solution

  • Based on the comments provided by Andy,

    Wherever you have a limit, then from there you can thrown an error. There is no specific convention for the stack to have a limit or throw an error. Though it can do such.

    The operating system can also impose different limits:

    • limits on the virtual machine
    • limits of operating system against an individual application