Why would it be necessary to constrain a stack size?



This exercise states that the size of a stack can be constrained to limit resources used. What would be a reason for doing that?


While modern computers have significant resources available, there can be reasons to explicitly place size limits on data structures such as a stack. For example, in some instances code can enter into a condition known as an infinite loop where steps are repeated forever. If that code involved placing items onto a stack, then the size of the stack would grow to consume all the available memory allocated to the program. However, if the stack size is limited, then the program would encounter an error condition before that happened.