bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-gnulib] alloca


From: Bruno Haible
Subject: Re: [Bug-gnulib] alloca
Date: Thu, 13 Nov 2003 13:10:29 +0100
User-agent: KMail/1.5

Paul Eggert wrote:
> * Is there a good heuristic for determining the maximum safe argument
>   to give to alloca?  For example, if the machine's page size is 8192
>   bytes and stacks are allocated on page boundaries, shouldn't
>   alloca's argument be at most 8192 (or perhaps even 8191)?
>
>   Ideally, I'd like to see this "maximum safe alloca" value
>   automatically configured.

This maximum safe argument should IMO be computed as

    guaranteed stack size / maximum call stack depth

i.e. it will depend on the application. In CLN I could choose 64 KB
because the call stack depth is <= 5 or 7 (transcendental functions call
multiplication, multiplication call FFT, FFT call small multiplication),
and the guaranteed stack size (even on MacOS X) is 0.5 MB.

In applications that use a recursion depth of 200 or 500 routinely
(clisp does this for example), the maximum safe size will be around 1 KB.

It's not related to the machine page size.

> * Why is the code less pretty in C?  What general problems make it
>   uglier in C?

1) In C you need an extra line of code for deallocating the stack:

     {
       CL_ALLOCA_STACK;
       ...
       CL_DEALLOCATE_STACK;
     }

2) In C++, a "return" or "goto" that leaves the scope of the compound
   statement performs the cleanup actions automatically. Whereas in C
   you have to make sure yourself that all branches of the control flow
   go through CL_DEALLOCATE_STACK.

Bruno





reply via email to

[Prev in Thread] Current Thread [Next in Thread]