Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:5608 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 82848 invoked by uid 1010); 20 Nov 2003 09:49:10 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 82824 invoked from network); 20 Nov 2003 09:49:10 -0000 Received: from unknown (HELO mail.zend.com) (192.117.235.230) by pb1.pair.com with SMTP; 20 Nov 2003 09:49:10 -0000 Received: (qmail 7062 invoked from network); 20 Nov 2003 09:49:07 -0000 Received: from guardian.zend.office (HELO andi-laptop.zend.com) (10.1.1.4) by int.zend.com with SMTP; 20 Nov 2003 09:49:07 -0000 Message-ID: <5.1.0.14.2.20031120114209.0501bb18@127.0.0.1> X-Sender: andi@127.0.0.1 X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Thu, 20 Nov 2003 11:48:57 +0200 To: internals@lists.php.net Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Subject: Using do_alloca() instead of emalloc() From: andi@zend.com (Andi Gutmans) 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. 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