Datesfat Chicks
5/5/2011 10:46:00 PM
On Thu, 05 May 2011 21:17:09 +0100, Ben Bacarisse
<ben.usenet@bsb.me.uk> wrote:
>"Kleuskes & Moos" <kleuske@xs4all.nl> writes:
>
>> On May 5, 11:37 am, boltar2...@boltar.world wrote:
>>> If a program recurses too deeply there's always a chance that it could
>>> run out of stack space and die with a SIGSEGV. Is there any API that can
>>> tell you how much stack space is left or some other method to prevent this
>>> in C/C++? I realise I could catch the signal but thats a pretty damn ugly
>>> way to do it.
>>
>> The only proper way to avoid stack-overflows is to prevent it from
>> happening in the first place. If at all possible (and frequently it
>> is) avoid recursion, if it's unavoidable, as it sometimes is, make
>> sure your design prevents those situations from arising in the first
>> place.
>
>I find this answer interesting, mainly because I think is suggests a
>very different view about programming. I would not try to avoid
>recursion "if at all possible". In general I consider that it is up to
>the system to provide the resources needed by a program and this
>includes stack for a reasonable amount of recursion. These resources
>can run out of course, and the stack is special in that few languages
>provide any way to handle its exhaustion elegantly, but that does not
>seem enough reason to design out all recursion.
>
>There are special cases: some environments are severely resource limited
>but there's no indication that the OP is using such a system and,
>anyway, I don't think you can make general rules from specific situations.
>
>> Trying to solve a design problem by imposing artificial limitations
>> seems a bad idea.
>
>Isn't this what you are doing? Isn't the ban on recursion not an
>artificial limitation?
The restrictions on stack depth are no different than the restrictions
on memory size or disk space that are present on any computer system.
These limits have been relaxed over time, and certainly programs will
run today on a typical computer that would not have run 10 years ago
on a typical computer.
"Don't use recursion" seems to be logically the same as "don't declare
very large arrays" or "don't create really big files". It is
dependent on the technology of the day, rather than being an absolute
standard.
These days I have a few files on my server that are on the order of
20G. That would have been unthinkable 10 years ago.
DFC