472,988 Members | 3,092 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,988 software developers and data experts.

How to save state of a recursive function?

Dear Members,
I have written a recursive function. It calls itself recursively. It
is placed inside a thread. So I can easily suspend and resume the
thread to suspend or resume the function as well.

My problem is:

I run the application. Then run the thread. So the function also runs
and makes stacks on stacks and goes deep and deep. I want to save an
arbitrary state of the function (for example the depth or anything
needed to resume). Then close the application. Then restart the
application and reload what I saved and finally resume the thread.

In detail I need to save "process context" of the application
somewhere and reload it again to return to the saved point of app.
It is like hibernating Windows!

Can anybody help me?
Thanks in advance.
Jun 27 '08 #1
3 2539
AliRezaGoogle wrote:
I have written a recursive function. It calls itself recursively. It
is placed inside a thread. So I can easily suspend and resume the
thread to suspend or resume the function as well.
No. Just no. Redesign this. Suspending threads is evil. Can't you use an
iterator for this?
My problem is:

I run the application. Then run the thread. So the function also runs
and makes stacks on stacks and goes deep and deep. I want to save an
arbitrary state of the function (for example the depth or anything
needed to resume). Then close the application. Then restart the
application and reload what I saved and finally resume the thread.
The managed environment doesn't give you enough access to process state to
accomplish this. Tying up the state in the stack is no good if you need to
be able to store it.

Rewrite your function so it's not recursive. Or indeed a function. C# isn't
an O-O language for nothing. State is supposed to be contained in objects;
going against this is just inviting trouble. What you want to do would work
a lot better in a pure functional language.

--
J.
http://symbolsprose.blogspot.com
Jun 27 '08 #2
I suggest you replace the recursive function with a depth-first-search. You
can look at the (free) library I have written for DFS, and/or download the
documentation at http://www.lulu.com/content/1995848.

Your nodes to the DFS can be made Serializable. You save the search by
writing out the last node delivered (which points to its parent, etc, up to
the root). You can reload the node and start the search at the point it
left off by passing the last node as the (new) "root" to a new DFS.
"AliRezaGoogle" <as*******@yahoo.comwrote in message
news:2f**********************************@u36g2000 prf.googlegroups.com...
Dear Members,
I have written a recursive function. It calls itself recursively. It
is placed inside a thread. So I can easily suspend and resume the
thread to suspend or resume the function as well.

My problem is:

I run the application. Then run the thread. So the function also runs
and makes stacks on stacks and goes deep and deep. I want to save an
arbitrary state of the function (for example the depth or anything
needed to resume). Then close the application. Then restart the
application and reload what I saved and finally resume the thread.

In detail I need to save "process context" of the application
somewhere and reload it again to return to the saved point of app.
It is like hibernating Windows!

Can anybody help me?
Thanks in advance.

Jun 27 '08 #3
On Jun 8, 9:49*pm, "Fred Mellender" <nospamPlease_fred...@gmail.com>
wrote:
I suggest you replace the recursive function with a depth-first-search. *You
can look at the (free) library I have written for DFS, and/or download the
documentation athttp://www.lulu.com/content/1995848.

Your nodes to the DFS can be made Serializable. *You save the search by
writing out the last node delivered (which points to its parent, etc, up to
the root). *You can reload the node and start the search at the point it
left off by passing the last node as the (new) "root" to a new DFS.

"AliRezaGoogle" <asemoo...@yahoo.comwrote in message

news:2f**********************************@u36g2000 prf.googlegroups.com...
Dear Members,
I have written a recursive function. It calls itself recursively. It
is placed inside a thread. So I can easily suspend and resume the
thread to suspend or resume the function as well.
My problem is:
I run the application. Then run the thread. So the function also runs
and makes stacks on stacks and goes deep and deep. I want to save an
arbitrary state of the function (for example the depth or anything
needed to resume). Then close the application. Then restart the
application and reload what I saved and finally resume the thread.
In detail I need to save "process context" of the application
somewhere and reload it again to return to the saved point of app.
It is like hibernating Windows!
Can anybody help me?
Thanks in advance.- Hide quoted text -

- Show quoted text -
Thank you!
I'll go for this. It seem that DFS search can solve my problem. Thank
you very much.
Jun 27 '08 #4

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

Similar topics

2
by: Someonekicked | last post by:
I know this might not be the right group to post this question, though I am looking for any help or redirection to the right group. Its a small program, and I have to model it using state...
7
by: John J. Hughes II | last post by:
I need to save a DWORD to the sql server, the below posts an error, any suggestions on what I am doing wrong. I have the column in the sql server defined as an int since unsigned int is not valid....
7
by: Javaman59 | last post by:
This is about finding the right point at which to save user entered data in the registry, so that when the application is restarted, the saved values will be restored. I want this behaviour to be...
6
by: nilavya | last post by:
HI, I have got a C++ application involving State machine. Now I have got too many states and too many events which changes the state of the Staet machine. So my code is somewhat unmanageable....
1
by: Irene | last post by:
Hello all! I'm creating a web site in ASP.NET (VB.NET). One of the requirements was to allow users to create orders going through several steps. A must have is to have an option to save the work...
14
by: fdu.xiaojf | last post by:
Hi, I have a program which will continue to run for several days. When it is running, I can't do anything except waiting because it takes over most of the CUP time. Is it possible that the...
1
by: Rameel | last post by:
Friends, I'm probably being more critical with VB.Net Windows application. I have Developed VisualStudio 20005 VB.Net Windows application how willl i be able to save a specific record into my...
14
by: squrel | last post by:
Hello everyone, I m using some button using toolbar such as Add,Save,View,.... my save button is not working.... it doesnt give me any error but does not save to my database.... or showing in my...
1
by: Allen | last post by:
I'm using the turtle module in Python. Is there a way to save the turle state at any moment for recursive algorithms to easily return the turtle to an earlier point for another branch/etc? ...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.