On 6/30/06, Adam Zey <azey@xxxxxx> wrote:
I think that will work, but there is one huge improvement you can make. You are making millions of copies of your work array! Not only do you pass the entire array by value recursively, but foreach makes copies of the arrays it loops through! So who knows how many copies of the darned work array are being spawned left and right. This can be a memory leak, consuming lots of memory until it finishes the recursion.
Yipes!
The first thing you can do is tell the function the array is to be handled by reference: function processthread($post_id, &$workArr) {
Added your suggestion, works fine.
You never change the work array, I think, so you can just keep referring back to the original.
yes, that is correct. $workArr is never modified.
The second thing to do is to make the foreach work on references instead of copies. I actually think that since what we have in our function is now a reference, the foreach WILL NOT copy it.
Anyone have any ideas on this? Is the foreach loop in fact copying $workArr? And how could we tell (test for it) if it were?
But if it still does, there is always the fallback of doing a foreach on array_keys($workArr). Then each $value would be the key, which you'd use to reference $workArr.
I'm sorry, you lost me here a bit.
Regards, Adam.
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php