Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:5669 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 95376 invoked by uid 1010); 22 Nov 2003 19:45:23 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 95212 invoked from network); 22 Nov 2003 19:45:22 -0000 Received: from unknown (HELO shiva.mind.de) (212.42.230.204) by pb1.pair.com with SMTP; 22 Nov 2003 19:45:22 -0000 Received: from trillian.mshome.net (p508EA138.dip.t-dialin.net [80.142.161.56]) by shiva.mind.de (Postfix) with ESMTP id BE17897C7B; Sat, 22 Nov 2003 20:45:20 +0100 (CET) Date: Sat, 22 Nov 2003 20:45:50 +0100 X-Mailer: The Bat! (v2.00) Educational Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <9349135392.20031122204550@marcus-boerger.de> To: Andi Gutmans Cc: internals@lists.php.net In-Reply-To: <5.1.0.14.2.20031120114209.0501bb18@127.0.0.1> References: <5.1.0.14.2.20031120114209.0501bb18@127.0.0.1> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Using do_alloca() instead of emalloc() From: helly@php.net (Marcus Boerger) Hello Andi, Thursday, November 20, 2003, 10:48:57 AM, you wrote: > Hey, > I've been taking a look at the __autoload problem. During that time I saw > that lots of places in the code (especially reflection API) use > zend_str_tolower_dup(). > In most of these cases it would be much more efficient to use > do_alloca()/free_alloca() because that usually uses alloca() which > allocates on the stack. Well Zeev and you told us to never it :-) > Simplified example from reflection API code: > lcname = zend_str_tolower_dup(name_str, name_len); > if (zend_hash_find(&ce->properties_info, lcname, name_len + 1, (void **) > &property_info) == FAILURE) { > efree(lcname); > /* Error message */ > return; > } > efree(lcname); > This should really be: > lcname = do_alloca(name_len+1); > zend_str_tolower_copy(lcname, name_str, name_len+1); > if (zend_hash_find(&ce->properties_info, lcname, name_len + 1, (void **) > &property_info) == FAILURE) { > free_alloca(lcname); > /* Error message */ > return; > } > free_alloca(lcname); > There are two times where you really shouldn't use do_alloca/free_alloca: > a) If you're in code which requires a regular malloc() don't use them (the > fallback is emalloc()). > b) Only use them in functions which are about to return. They shouldn't be > used in places like the main zend_execute loop because it would just make > the stack grow more and more (in almost all cases where > zend_str_tolower_dup() is being used, do_alloca/free_alloca are applicable). > I need to go away for the weekend now but it be cool if people here would > at least take care of this in their code (such as reflection API code). > Thanks, > Andi -- Best regards, Marcus mailto:helly@php.net