Re: Just some interesting facts
- Posted by Robert Craig <rds at RapidEuphoria.com> Dec 05, 2005
- 496 views
Jason Gade wrote: > akusaya wrote: > > Try this: > > > > object a > > a = 0 > > for i = 1000000 to 1 by -1 do > > a = {i, a} > > a[1] = a > > end for > > print(1,a) > > A message like "A stack overflow was encountered at address 0043d335" > > will appear after about two thousand. > > It looks like the stack overflow is coming from the print statement, not the > for loop or sequence creation. I can get it to pass by commenting out or > removing > the print statement. Yes. It builds a sequence that's nested a million levels deep, but print() fails because print is implemented using a recursive C routine, and it eventually blows the hardware stack limit that's set when the interpreter is built. I've been aware for a long time that this type of thing could happen. I recoded some recursive routines as non-recursive, to reduce the risk, but when you are dealing with recursive data structures, recursion is very handy. If you replace print() with pretty_print(), it will work, because pretty_print() is written in Euphoria. I'll boost the stack limit in the next release, but there will always be a limit, if I want reasonable efficiency. Unless someone knows how to get DOS or Windows to automatically enlarge the stack. In practice, people never seem to hit the existing limit unless they are just fooling around. > > procedure b(object c) > > ?c > > b(c+1) > > end procedure > > b(0) > > > > > > After more than 600000 depth, it still runs! > > > > > > So Eu stack is better than C stack. Or Eu doesn't use real stack. Euphoria manages it's own call stack for running Euphoria routines. It will grow that stack as required. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com