3 ms·
Recursive functions using stacks are more expensive in terms of memory than explicit recursion due to more careful state saving.
by richardwhiuk 3y ago
Recursive functions using stacks are more expensive in terms of memory than explicit recursion due to more careful state saving.
- explaininjs 3y agoCould you explain what you mean by these two “types” of recursive functions here?
- quotemstr 3y agoAt a minimum, each frame of a recursively implemented algorithm in a typical AOT system without special allocations (say, milquetoast GCC 9) needs to save on each frame the return address in addition to whatever data the algorithm itself needs. Add on top of that a frame pointer, padding for stack alignment, and so on and you can end up with significant overhead you can avoid implementing the same algorithm with an explicit stack.