[mercury-users] Stack overflow detection?

Zoltan Somogyi zs at cs.mu.OZ.AU
Thu May 13 02:21:13 AEST 2004


On 12-May-2004, obo at ruk.cuni.cz <obo at ruk.cuni.cz> wrote:
> The redzone mechanism is preferred because such code is faster if there is
> still enough space on the stack?

Yes. If running out of stack is an exceptional case, and in most applications
it is, then the system should be optimized for the non-running-out case.

> It is perfectly
> correct to simply reject an input sentence on the basis of "memory
> exhaustion", such a sentence is definitely not one of the "simple ones"
> I'm selecting.

Ah. In that case, a reasonably simple solution should be possible.
How simple depends on whether your programs runs out of memory in a small
set of simply predictable places, or not.

If yes, I can write a predicate that checks if either stack is about to be
exhausted, and throws an exception if the answer is yes. You would then call
this predicate at starts of the recursive predicates that can run you out of
stack, and catch any resulting exceptions.

If the number of places where this call insertion would have to be done is too
high, I could create a compiler option to insert this call at the start of all
the predicates in the modules compiled with this option.

I am writing this from Uppsala on a visit to the university here. My time
here is limited, and I want to exploit it fully, so I won't be able to
write the code you need until I get back to Melbourne next week.

Zoltan.
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list