httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dean Gaudet <>
Subject Re: alloca (was Re: cvs commit: apache-1.3/src/modules/standard mod_log_referer.c)
Date Mon, 25 May 1998 05:46:16 GMT
That's the implementation I meant when I said "we can implement something
like alloca everywhere" (or however I said it)... it's a hack, and it's
required because the gcc source code uses alloca(), so it needs an
alloca() implementation to bootstrap itself.  It doesn't require any
assembly to work, my guess is they use it for a few optimizations. 

As far as how gcc implements alloca() for stuff it compiles -- it's
probably done in terms of internal abstract register names like "frame
pointer" and "stack pointer".  It's all stuff the front-end can do, the
back-end doesn't need any knowledge of it.  In fact alloca() is
essentially how variable sized arrays are implemented (which you need for
pascal, modula-3, and which are an extension in GNU C). 


On Sun, 24 May 1998, Marc Slemko wrote:

> On Sun, 24 May 1998, Dean Gaudet wrote:
> > alloca essentially has to use compiler-dependant features... it's either
> > implemented as a builtin (as it is in gcc), or using extensions (like
> > inline assembly, which is how it's done in WATCOM C). 
> /usr/src/contrib/gcc/alloca.c:
> /* alloca.c -- allocate automatically reclaimed memory
>    (Mostly) portable public-domain implementation -- D A Gwyn
>    This implementation of the PWB library alloca function,
>    which is used to allocate space off the run-time stack so
>    that it is automatically reclaimed upon procedure exit,
>    was inspired by discussions with J. Q. Johnson of Cornell.
>    J.Otto Tennant <> contributed the Cray support.
>    There are some preprocessor constants that can
>    be defined when compiling for your specific system, for
>    improved efficiency; however, the defaults should be okay.
>    The general concept of this implementation is to keep
>    track of all alloca-allocated blocks, and reclaim any
>    that are found to be deeper in the stack than the current
>    invocation.  This heuristic does not reclaim storage as
>    soon as it becomes invalid, but it will do so eventually.
>    As a special case, alloca(0) reclaims storage without
>    allocating any.  It is a good idea to use alloca(0) in
>    your main control loop, etc. to force garbage collection.  */
> This is from the FreeBSD gcc source.  It is using malloc and free.
> There are processor specific assembly implementations, but does gcc have
> them for every processor or does it use the malloc/free one for some?  

View raw message