0

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?

mfaani
  • 33,269
  • 19
  • 164
  • 293
  • Possible duplicate of [What is a stack overflow?](https://stackoverflow.com/questions/1110138/what-is-a-stack-overflow) – Andy Thomas Oct 25 '18 at 13:21
  • That's a good question. But different. That's talking about a software's call stack. I'm purely asking about the implementation. That does it crash at the stack level or the app level? Basically who takes ownership of crashing the app/program? – mfaani Oct 25 '18 at 13:40
  • Are you referring to a call stack, or a generic stack as a data structure within an application? – Andy Thomas Oct 25 '18 at 13:48
  • I'm not referring to call stack in particular. Just want to know should a generic stack (call stack is obviously one example of a stack) be responsible for throwing the overflow error or the app which is using the stack? – mfaani Oct 25 '18 at 13:55
  • The call stack is handled differently than data structures within the application. For the former, see [stack overflow on wikipedia](https://en.wikipedia.org/wiki/Stack_overflow). For the latter, a stack might have a fixed upper-bound on size or not. If it does, then it needs to do something graceful (e.g., throw an exception) if an attempt is made to exceed that bound. Regardless, there can still be an effective limit established by any limitations on heap size, causing the application to run out of memory. – Andy Thomas Oct 25 '18 at 14:11
  • So to conclude you're saying a stack **may or may not have a size limit**. If it does then it will throw an exception. If not then it will just keep doubling down until the the application runs out of memory. So basically there is no convention for stacks to handle overflows. Yet some stack implementations may do such. Is that a correct summary? – mfaani Oct 25 '18 at 14:19
  • There can be a per-stack size limit on data structures. There is typically a limit established by available operating system resources. There can be a limit established by a virtual machine, if any. The behavior, and the error, and the customary name depend on whether it's a call stack or an application data structure, and what limit has been reached. This leads to this question being rather broad. You can ask more specific questions separately. – Andy Thomas Oct 25 '18 at 14:40

1 Answers1

0

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
mfaani
  • 33,269
  • 19
  • 164
  • 293