Return-Path: Delivered-To: new-httpd-archive@hyperreal.org Received: (qmail 27520 invoked by uid 6000); 22 May 1998 18:48:38 -0000 Received: (qmail 27414 invoked from network); 22 May 1998 18:48:36 -0000 Received: from epic18.stanford.edu (171.64.15.51) by taz.hyperreal.org with SMTP; 22 May 1998 18:48:36 -0000 Received: (from akosut@localhost) by epic18.Stanford.EDU (8.8.8/8.8.4) id LAA00398; Fri, 22 May 1998 11:48:30 -0700 (PDT) Date: Fri, 22 May 1998 11:48:30 -0700 (PDT) From: Alexei Kosut To: new-httpd@apache.org Subject: Re: cvs commit: apache-1.3/src/modules/standard mod_log_referer.c In-Reply-To: <3.0.3.32.19980522112711.008c4450@hyperreal.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: new-httpd-owner@apache.org Precedence: bulk Reply-To: new-httpd@apache.org 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 Stanford University, Class of 2001 * Apache *