httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexei Kosut <ako...@leland.Stanford.EDU>
Subject Re: cvs commit: apache-1.3/src/modules/standard mod_log_referer.c
Date Fri, 22 May 1998 18:48:30 GMT
On Fri, 22 May 1998, Brian Behlendorf wrote:

> At 07:00 PM 5/22/98 +0100, Ben Laurie wrote:
> >Err? Surely alloca only hits the kernel if you have to grow the stack as
> >a result? And, of course, it gives the memory back much sooner than
> >pstrdup does.
> 
> Like I said, I don't know.  Others have pointed out man pages that say it's
> highly machine dependent and should be avoided in cross-platform code.  On
> the other hand we use it in a couple places in our core code, so it must
> work well enough.  None of the other modules use it however.  It'd be
> interesting to see benchmarks...

My understanding was that one should never use alloca. Not if one expects
code to work correctly, or at all.

There are a few uses of alloca() in http_main, but they are all in
Win32-only sections. Presumably, the alloca() in Windows has well-defined
and correct behavior. Or at least it doesn't break anything. I wouldn't
trust it normally (I don't trust it on Windows either, but it seems to
work).

One thing to note is that successful use of alloca() depends on the
compiler intervening on alloca()'s behalf. I personally would not suspect
that all compilers correctly support it. gcc does (actually, gcc supports
alloca as a builtin, rather than calling the system library, so it
probably works all right), but I wouldn't guarantee that every compiler
does. And I'd be wary of Apache timeouts' use of longjmps and that
interaction with alloca.

If we want temporary memory, why not just use malloc() and free()?
Or a large defined buffer on the stack? That seems to work well for the
rest of the world... And besides, using palloc() for a couple of bytes of
memory that won't be freed for a bit is probably all right. Requests go
quickly.

And thanks to the nice Sun people, from the Solaris alloca(3C) man page:

"alloca() is machine-, compiler-, and most of all, system-dependent. Its
use is strongly discouraged."

-- Alexei Kosut <akosut@stanford.edu> <http://www.stanford.edu/~akosut/>
   Stanford University, Class of 2001 * Apache <http://www.apache.org> *




Mime
View raw message