array_reverse() and garbage collection

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

 



Hi,]

So I've been thinking, because occassionally I do, about
array_reverse() and how to implement it. Of course, it's entirely
theoretical, because it would a total waste of time. But I'm wondering
which of two methods would be best.

1. Do it "correctly" and in place. ie, loop through the the first half
of the array once swapping element 0 with the end one, element 1 with
the next to last one and so on.

2. Loop thru the array once creating a new one. Normally this would
take up a little more memory because you end up with two copies of the
array in memory just before the end of the function. But what if you
set the original element to null once you've assigned it to the new
array? The most memory I can see it using is two copies of one
element. But only if garbage collection kicks in before you start on
the next element. Does garbage collection kick in that often? From
what I remember from an article by Derick Rethans, if the refcount is
zero, then it gets cleaned up.

Cheers.

-- 
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated December 5th)

-- 
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