473,396 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 2565
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.