On 25.03.2019 0:58, Mr Flibble wrote:
> On 24/03/2019 21:18, Paavo Helde wrote:
>> On 24.03.2019 18:48, Bonita Montero wrote:
>>>>> You're dealing with problems that not exist. Stack-overflows
>>>>> almost never happen. The only case which might tigger a stack
>>>>> overflow realistically is a massively misuse of alloca(). But
>>>>> using alloca() is untypical for C++-programs.
>>>
>>>> Nonsense.
>>>
>>> No, not nonsense. No one cares about stack-overflows at least in
>>> userspace. With Windows the default stacksize is one MB and with
>>> Linux its 2MB. No one does recursions that eat so much stack-size.
>>
>> No one does such recursion because it does not work in C++. Stack
>> overflow is one of nastiest UB-s in C++. Instead, people take pains to
>> rewrite recursive algorithms via loops and dynamic data structures on
>> heap.
>
> I assume you are joking based on what you write next because that is
> simply bullshit.
Probably you misunderstood me somehow. What I wanted to say is that
certainly there are some people who would like to use deep recursive
algorithms in C++. A million iteration loop is perfectly fine, so why
should a million deep recursion not be? Alas, currently they can't
because the stack size is pretty limited and there are no safeguards.
Even if the recursion depth can be artificially bounded like in your
solution, it would not be safe to go anywhere near the max stack size as
there are too many uncontrollable factors affecting the stack memory usage.
As you said yourself, sometimes aborting too deep recursion with an
exception is acceptable, sometimes it is not. If it is not, then I
cannot use a recursive solution at all, period. It just does not work. I
have to rewrite my solution as non-recursive, and there would be no
point to keep the recursive variant around. So that's why Bonita is not
seeing deep recursive functions using up all the stack.
If an exception is acceptable, then I could come closer to utilizing the
whole stack, but nowhere near 100% as this would be way too dangerous,
especially with a rigid compile-time constant like in your solution. To
play it safe in a library used in unknown environments I would not dare
to use over half of the default stack space. So again Bonita is not
seeing a recursive function using up all the stack.