Re: Package proposal: Mail_Mime (alternative)
| From: | Heino H. Gehlsen | Date: | Fri, 15 Aug 2003 15:49:53 +0000 |
| Subject: | Re: Package proposal: Mail_Mime (alternative) | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-19825@lists.php.net to get a copy of this message | ||
> > in the hope of improvements I have done a lot of parsing by reference
internally.
>
> Oh bad move.
>
> Pass by reference is slower in PHP4. PHP4 has reference counting which
> prevent copies from being made if the variable is not actually modified.
>
> $foo = 'foo'; ('foo' in memory, ref counter 1)
> $foo = $bar; ('foo' in memory, ref counter 2)
> $bar = 'bar' ('foo' and 'bar' in memory, each with ref counter 1)
Ehh... I don't see an parsing by reference (not &'s) in your example...
Admitted, I don't know PHP's internals and I'm used to Java, so I guess
it's the clasic parsing by value / refecence problem over again...
What I ment is that I'm passing the really heavy variables by referance from
method to method loke so:
--------------
function & a(&$foo, $bar) {
return b($foo, $bar);
}
function & b(&$foo, $bar) {
return c(&$foo, $bar);
}
function & c($foo, $bar) {
$return = &$foo;
$return .= ' ';
$return .= $bar;
return $return;
}
$foo = 'Reeeeaaally large string (complete message
body)........................................... Really many chars...';
$bar = ';-)';
echo a($foo, $bar);
--------------
For years I been doing this to save memory when working with (potentially)
large variables - is it bad form in PHP ?
If it's an object one have to do it, but what if it's a potentially very
large string/array?