Re: Reference return buggy notice?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jochem Maas wrote:
Stut wrote:
Say you have a function that builds a fairly large array and then
returns it. If you just return it as usual PHP will make a copy of that
array and therefore use twice the amount of memory than it needs to.

php has something called 'copy on change' so until an attempt to make a change on
the returned array is made the doubling of memory usage doesn't occur. afaik.

Interesting. Didn't know that.

are there any benchmarks either way?

I've never come across any, but I don't need a benchmark to know that the potential for double the memory use is best avoided.

References also provide a way to return more than one variable from a
function, but I doubt many PHP developers come across the need to do that.

an example is returning the total count of a given sql statement in an
'by reference' argument whilst returning a 'paged' result set.

Good example. Not one I'd think of because all my SQL is wrapped up in classes that expose that stuff in other ways.

Where in the manual does it say that? I've never seen it and I can't
find it.

say what?

In the email I replied to from M. Sokolewicz...

As the manual states "if you think you need to use references, think again, you probably don't."

Just wondering where it says that.

-Stut

--
http://stut.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux