Why does the call stack have a static maximum size?
Having worked with a few programming languages, I've always wondered why the thread stack has a predefined maximum size, instead of expanding automatically as required. In comparison, certain very common high level structures (lists, maps, etc.) which are found in most programming languages are designed to grow as required while new elements are added, being limited in size only by available memory, or by computational limits (e.g. 32 bit addressing). I'm not aware though of any programming languages or runtime environments where the maximum stack size isn't pre-limited by some default or compiler option. This is why too much recursion will result very quickly in a ubiquitous stack overflow error/exception, even when only a minimal percentage of the memory available to a process is used for the stack. Why is it the case that most (if not all) runtime environments set a maximum limit for the size a stack can grow at runtime?
Having worked with a few programming languages, I've always wondered why the thread stack has a predefined maximum size, instead of expanding automatically as required.
In comparison, certain very common high level structures (lists, maps, etc.) which are found in most programming languages are designed to grow as required while new elements are added, being limited in size only by available memory, or by computational limits (e.g. 32 bit addressing).
I'm not aware though of any programming languages or runtime environments where the maximum stack size isn't pre-limited by some default or compiler option. This is why too much recursion will result very quickly in a ubiquitous stack overflow error/exception, even when only a minimal percentage of the memory available to a process is used for the stack.
Why is it the case that most (if not all) runtime environments set a maximum limit for the size a stack can grow at runtime?