Date: 05/31/01
- Next message: darcy w. christ: "[phplib] logging in before authentication"
- Previous message: James Johnson: "Re: [phplib] PHP and recursion"
- In reply to: Roy Huggins: "[phplib] PHP and recursion"
- Next in thread: D. Sebastien Taggart: "FW: [phplib] PHP and recursion"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hello Roy,
Recursion is fine but you have to know how much it could take before
you use it. I personally use it and haven't experienced any troubles
before, but I doubt that my recursive calls were more then 10 levels
deep.
It seems to me that you pass a lot of data to the recursive call. Try
to avoid this. Find the variables that are absolutely necessary for
the call. Don't do much data processing (db accesses, etc.) in
recursive functions. Use references. It would be better to define a data
structure and fill it without recursion, and then use a recursive
function that operates with references to the data, not the data itself.
Thursday, May 31, 2001, 6:07:03 PM, you wrote:
RH> My question is not related to PHPLib specifically, for which I apologize. But
RH> the members of the list have oft displayed good knowledge of the underworkings
RH> in PHP and I'd like to get some insight into something I've run into recently.
RH> I recently built a pair of classes whose purpose is to create a tree of TreeNode
RH> objects in which each node has one parent, many children and an array of
RH> arbitrary data. Performing operations on these trees uses a lot of recursion, of
RH> course. Upon testing one function that traverses the tree, creating an array of
RH> path illustration strings through the tree (i.e. $paths[0] ==
RH> "root:node1:node2", $paths[1] == "root:node1:node4:node7"), PHP quit while
RH> complaigning about using too much memory. My script was using a whopping 8 megs!
RH> I examined my code to see if I was doing something stupid to fill up the RAM and
RH> didn't find anything (which, of course, doesn't mean it isn't there. :) But I
RH> wanted to get some more info on how PHP deals with recursion and whether or not
RH> people have any comments/caveats to express on the issue. I've been spoiled by
RH> Scheme and find that recursion is wonderful at times. I'd like to know if it's
RH> really a good idea to use it that much in PHP.
-- Best regards, Maxim Derkachev mailto:max.derkachev <email protected> System administrator & programmer, Symbol-Plus Publishing Ltd. phone: +7 (812) 324-53-53 www.books.ru, www.symbol.ru--------------------------------------------------------------------- To unsubscribe, e-mail: phplib-unsubscribe <email protected> For additional commands, e-mail: phplib-help <email protected>
- Next message: darcy w. christ: "[phplib] logging in before authentication"
- Previous message: James Johnson: "Re: [phplib] PHP and recursion"
- In reply to: Roy Huggins: "[phplib] PHP and recursion"
- Next in thread: D. Sebastien Taggart: "FW: [phplib] PHP and recursion"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

