473,508 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Recursive Call

Hi all,

What is the better way to do a Recursive call, avoiding StackOverflow???

I've Tried Something like this:

Sub MyRecursiveSub()

thread.currentthread.sleep(2000)
Call MyRecursiveSub()

End Sub

but after many executions (43011), the stack overflow will be raised.
Thanks in advance
Nov 21 '05 #1
3 1069

"Fabio" <fa***@glb.com.br> wrote

What is the better way to do a Recursive call, avoiding StackOverflow???
You have to give it a way to exit!

I've Tried Something like this:

Sub MyRecursiveSub()

thread.currentthread.sleep(2000)
Call MyRecursiveSub()

End Sub

but after many executions (43011), the stack overflow will be raised.

That does not really show what you want to do, does it?

If that is what you want to happen, you could write it like this to
avoid the error:

Do
Sleep(2000)
Loop

While that would do what you posted, it is not very useful...
What is it you really want to do?

LFS

Nov 21 '05 #2
But I Can't permit this! Because it's a listener aplication!

there is another way???

"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:OL**************@TK2MSFTNGP11.phx.gbl...

"Fabio" <fa***@glb.com.br> wrote

What is the better way to do a Recursive call, avoiding StackOverflow???


You have to give it a way to exit!

I've Tried Something like this:

Sub MyRecursiveSub()

thread.currentthread.sleep(2000)
Call MyRecursiveSub()

End Sub

but after many executions (43011), the stack overflow will be raised.

That does not really show what you want to do, does it?

If that is what you want to happen, you could write it like this to
avoid the error:

Do
Sleep(2000)
Loop

While that would do what you posted, it is not very useful...
What is it you really want to do?

LFS

Nov 21 '05 #3
Fabio wrote:
But I Can't permit this! Because it's a listener aplication!

there is another way???


You can't recursively call a function indefinately. At some point the
function has to return a result and close otherwise you'll end up with a
stack overflow as you've found out. Usually recursive loops are used to
search through a datatree for instance carrying the end result up to the
root. If you could tell us a bit what you are trying to accomplish, you
might get better help.

You say it's a listener application. Listening to what? A TCP/IP port?
Keyboard input?
--
Rinze van Huizen
C-Services Holland b.v.
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
5652
by: Steve Goldman | last post by:
Hi, I am trying to come up with a way to develop all n-length permutations of a given list of values. The short function below seems to work, but I can't help thinking there's a better way. ...
2
2869
by: | last post by:
OK: Purpose: Using user's input and 3 recursive functions, construct an hour glass figure. Main can only have user input, loops and function calls. Recursive function 1 takes input and displays...
4
2418
by: Nicolas Vigier | last post by:
Hello, I have in my python script a function that look like this : def my_function(arg1, arg2, opt1=0, opt2=1, opt3=42): if type(arg1) is ListType: for a in arg1: my_function(a, arg2,...
4
9035
by: Victor | last post by:
Hello, I've got a situation in which the number of (valid) recursive calls I make will cause stack overflow. I can use getrlimit (and setrlimit) to test (and set) my current stack size. ...
5
2789
by: Seong-Kook Shin | last post by:
Hi, I'm reading Steve's "C Programming FAQs" in book version, and have two question regarding to Q11.16 ... Also, a `return' from `main' cannot be expected to work if data local to main might be...
9
13151
by: Bill Borg | last post by:
Hello, I call a function recursively to find an item that exists *anywhere* down the chain. Let's say I find it five layers deep. Now I've got what I need and want to break out of that whole...
9
16796
by: Csaba Gabor | last post by:
Inside a function, I'd like to know the call stack. By this I mean that I'd like to know the function that called this one, that one's caller and so on. So I thought to do: <script...
4
2110
by: ThEoNeAnDOnLy | last post by:
I recently had an issue with my recursive project in class. Here is the code. // Recursion.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include...
3
4216
by: from.future.import | last post by:
Hi, I encountered garbage collection behaviour that I didn't expect when using a recursive function inside another function: the definition of the inner function seems to contain a circular...
3
2328
by: Davy | last post by:
Hi all, Sometimes I need to pass same parameter in recursive function. From my point of view, the style is redundant, and I don't what to use some global style like self.A, self.B, Is there any...
0
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7385
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3195
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1558
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.