Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

bazee

I need more stack space

This topic is 6153 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am using a recursive function for a path finding algorithm in my game. When I run out of stack space, the function gives up its work whether it has found the solution or not. The current algorithm I am using works really well, but only over the short distance of 10 units, since beyond that I run out of stack - i.e. the stack seems to only be able to store around 10 function calls! I want to increase this, but how? I am programming in Visual Basic 6. Thanks in advance for any help!

Share this post


Link to post
Share on other sites
Advertisement
OK, sorry I opened my mouth too quickly. I have solved my problem. All I did was reset my PC. Now my algorithm seems to work 50+ units! I am happy with it now. I am assuming the problem the first time round was that my PC was out of memory and slowly chugging away. But this leads me to a new question: does this mean that stack space is not constant? i.e. Windows or VB decides how much stack space is available at run time, and I have no guarantee my algo will work for all PCs, and no way to check how much stack space I have left?

Share this post


Link to post
Share on other sites
bazee,

I don''t know VB but in vc++6 the linker allocates stack space. Default is 1mb and you can change this. Don''t know what the max is but I suspect 2GB on win98. In assembly, you can preallocate stack segment with X amount of space or make the stack segment reside in code and data segments i.e. linear 2-4GB of address space.

Share this post


Link to post
Share on other sites
Assuming your arguments to your recursive function are reasonably sized, like 7 args or less, each a 4 byte or less value, you should be able to call your recursive function to a depth of hundreds, thousands, or even millions. Any standard Windows environment should be able to handle that. And any properly designed recursive function will check its depth as it goes if it has the potential of unbounded recursion. Also, recusrsive functions generally have a branching nature, which means a depth of more than 10, or maybe in an extreme case, a hundred about the max that is reasonable due to the combinatorial explosion.

As for the iterative suggestion above, stick with the recursive method. Iteration is for people who don''t understand recursion, abuse recursion, and want to save an extra 3 1/2 percent.

Share this post


Link to post
Share on other sites
VBs stack space is really really small. So small, it makes many recursive functions plain useless.

I just did a small test, and running from the IDE in Win98 with 64mb ram:


Private Sub Form_Load()
GoRecursion 1
End Sub

Sub GoRecursion(i As Long)
Debug.Print i
i = i + 1
GoRecursion i
End Sub

got to 6405 before dying.

Adding another 4 byte argument (unused), took this to 6236, and adding an 8 byte double argument brought it down to 6076.

But that seems really weird because I''ve had it run out of space in the mid 20s... I guess I have just booted this computer, but, it is small enough (and obviously unreliable enough) to justify writing your own "stack". Although it won''t be as fast, it will be allowed to be a bit bigger. And just to help you, the function AddressOf will return a function pointer (it isn''t in the MSDN because MS don''t like VB people working with pointers )

Trying is the first step towards failure.

Share this post


Link to post
Share on other sites
Well, 6k is a pathetic stack on any platform. Using C/C++ on the Windows platform (or any modern platoform) should not cause such problems. I would certainly hope so, anyway.

Share this post


Link to post
Share on other sites
If you can implement your algorithm iteratively, then clearly that's the way to go. If not (and you can't figure out a way to make Visual Basic give you more stack space), then perhaps there's some way you can limit the recursive depth of your function, assuming that your algorithm uses the recursion to refine the path, rather than to complete it. You could use something like this (I can't guarantee that this is valid VB code):

  
'-----------------------------
' call this function intially with 0 for depth
'-----------------------------
Sub Whatever(depth as Integer)
...
If depth < 16 Then
Whatever depth + 1
Else
...
EndIf
end sub



Edited by - merlin9x9 on July 17, 2001 1:13:06 AM

Share this post


Link to post
Share on other sites
Thanks for the help guys! As I said, the function is working satisfactorily now, my ghosts can chase my little pacman in mazes 100 x 100 tiles! I have learnt alot about trees and recursion and the tree structure from this game. One reason my algorithm performed slowly the first time, was that a new object was created for each node of the tree, using huge amounts of memory. Now the algorithm cleans up unused parts of the tree as it goes, making it much more efficient.

Share this post


Link to post
Share on other sites
VB''s stack space is so crap it''s not worth trying....

using a recursive quadtree function I got it recursing through a 2048x2048 height field no problems, VB couldn''t even do it at 64x64 :o no f''ng joke...

Jack;

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!