|
-
Nov 1st, 2004, 08:21 PM
#1
Thread Starter
Addicted Member
StackOverflow, Possible Workarounds?
I'm currently working on a program that creates a huge, and I mean huge, tree. The tree will probably have somewhere close to 36000 nodes. To create the tree I'm using a recursive algorithm which gives me a stackoverflow runtime error at about node #4000. What possible workarounds are there for this type of problem? Is there anyway to increase the amount of memory allocated to my program? This algorithm really only has to run once, so it's not a big problem that it is resource intensive.
-
Nov 2nd, 2004, 06:38 AM
#2
A treeof 36000 nodes should only have a depth of 2log 36000 < 20, that should in no way result in a stack overflow. What are you doing exactly?
If you only call your function once in your recursion step, you can change the function to use a while loop instead of recursion.
-
Nov 2nd, 2004, 11:46 AM
#3
Check how much stack space each function allocates. Try to reduce that.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 2nd, 2004, 11:08 PM
#4
PowerPoster
Originally posted by twanvl
A treeof 36000 nodes should only have a depth of 2log 36000 < 20
wut is that suppose to mean? where did that math formula come from?
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
-
Nov 3rd, 2004, 03:30 AM
#5
The depth of a perfectly balanced tree that splits into two nodes each time is log2(node count).
So a reason why you might have a stack overflow is that the tree is perhaps not balanced.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|