3 ms·
One of the things that people miss is that a "stack" was not just for recursion. A "stack" was also a small memory, single thread optimization because it allow
by bsder 3y ago
One of the things that people miss is that a "stack" was not just for recursion.
A "stack" was also a small memory, single thread optimization because it allows you to multiplex memory for function calls. If two functions do not call each other, they can share the memory used for their activation records.
Keeping track of this memory multiplexing in the compilers of the day would have been very hard and highly memory intensive--a stack solves that problem.
Without a stack, your memory usage (static) goes as O(n) with the number of functions. With a stack, your memory usage (dynamic) goes as O(n) with the depth of function calls. The memory usage of these two scenarios is wildly different.