Results 1 to 5 of 5

Thread: StackOverflow, Possible Workarounds?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    241

    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.

  2. #2
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771
    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.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  4. #4
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339
    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

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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
  •  



Click Here to Expand Forum to Full Width