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:[EMAIL PROTECTED]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php