Link to home
Start Free TrialLog in
Avatar of mrmazda
mrmazda

asked on

VB5 Stack Space Limits

Hi,
   Recently noted a confusing (to me) explaination of some utility code in the VB area of the Planet Source code website. The code was called "Overflow_Stack" and the code snippet determined the amount of VB Stack space. Here's it's explaination:
   Each VB App uses a single stack limited in size (20K in VB 3.0 Etc). The size can't be changed, so an "Out of Stack Space error can occur if your program performs uncontrolled recursion, such as a cascading event. Recursion occurs when a procedure calls itself (often repeatedly).
   I wonder if someone could give me a better example of "uncontrolled recursion"? Don't get the "cascading event/procedure calling itself examples.
   Is this guy talking about, say as a super theoretical example, having a procedure which contains an infinite Do While Loop, which itself calls other procedures(say each prints something) many many times over?
   Any ideas would be appreciated.
ASKER CERTIFIED SOLUTION
Avatar of traygreen
traygreen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of traygreen
traygreen

Basically a stack is a last in first out stucture.  A simple example of recursion would be solving a factorial.
eg 4! = 4*3*2*1 = 24
To solve this using recusion

Function Factorial (pNum as long) as Long
  if pNum = 0 Then
    Factorial = 1
  else
    Factorial = pNum * Factorial(pNum - 1)
  endif
end function