Regardless, though -- I think it's a bad idea to implement anything recursively that could even potentially overflow the stack. I mean, generally you have some sense of the kind of input a recursive function will be called on and what that will do in terms of stack space and can just make implementation decisions based on that. So say there's some function that takes a vector of n values and then does divide-and-conquer-style recursion so that the maximum stack size will be O(log n). If n could commonly be on the order of hundreds of thousands, would you implement this recursively? -- I wouldn't even though it is probably okay to do so ... that's basically all I'm saying.Not necessarily, some platforms provide the ability to detect a stack overflow. You usually can't do anything useful after one, but you can at least crash semi-gracefully. For example, Windows will raise a EXCEPTION_STACK_OVERFLOW SEH exception, which can be handled.
Show differencesHistory of post edits
#Actualjwezorek
Posted 07 February 2012 - 04:26 PM
#3jwezorek
Posted 07 February 2012 - 02:28 PM
Regardless, though -- generally I think it's a bad idea to implement anything recursively that could even potentially overflow the stack. I mean, generally you have some sense of the kind of input a recursive function will be called on and what that will do in terms of stack space and can just make implementation decisions based on that. So say there's some function that takes a vector of n values and then does divide-and-conquer-style recursion so that the maximum stack size will be O(log n). If n could commonly be on the order of hundreds of thousands, would you implement this recursively? -- I wouldn't even though it is probably okay to do so ... that's basically all I'm saying.Not necessarily, some platforms provide the ability to detect a stack overflow. You usually can't do anything useful after one, but you can at least crash semi-gracefully. For example, Windows will raise a EXCEPTION_STACK_OVERFLOW SEH exception, which can be handled.
#2jwezorek
Posted 07 February 2012 - 02:27 PM
Regardless, though -- generally I think it's a bad idea to implement anything recursively that could even potentially overflow the stack. I mean, generally you have some sense of the kind of input a recursive function will be called on and what that will do in terms of stack space and can just make implementation decisions based on that. So say there's some function that takes a vector of n values and then does divide-and-conquer-style recursion so that the maximum stack size will be O(log n). If n could commonly be on order of the hundreds of thousands, would you implement this recursively? -- I wouldn't even though it is probably okay to do so ... that's basically all I'm saying.Not necessarily, some platforms provide the ability to detect a stack overflow. You usually can't do anything useful after one, but you can at least crash semi-gracefully. For example, Windows will raise a EXCEPTION_STACK_OVERFLOW SEH exception, which can be handled.
#1jwezorek
Posted 07 February 2012 - 02:25 PM
Regardless, though -- generally I think it's a bad idea to implement anything recursively that could even potentially overflow the stack. I mean, generally you have some sense of the kind of input a recursive function will be called on and what that will do in terms of stack space and can just make implementation decisions based on that. So say there's some function that takes a vector of n values and then does divide-and-conquer-style recursion so that the maximum stack size will be O(log n). If n could commonly be on order of hundreds of thousands, would you implement this recursively? -- I wouldn't ... that's basically all I'm saying.Not necessarily, some platforms provide the ability to detect a stack overflow. You usually can't do anything useful after one, but you can at least crash semi-gracefully. For example, Windows will raise a EXCEPTION_STACK_OVERFLOW SEH exception, which can be handled.