- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Restore c programs data segment to reset globa...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2005 08:14 AM
04-05-2005 08:14 AM
Restore c programs data segment to reset globals
Is there a simple way to save the state of all global and static variables before the program runs, and restore the values.
Can I save the entire Text segment before execution, and restore it for the next cycle/thread. Is it text or data I need ?
What calls can I use to store and retrieve the entire text segment.
How efficient would this be compared to forking the programs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2005 08:30 AM
04-05-2005 08:30 AM
Re: Restore c programs data segment to reset globals
My approach would be to put all your globals
inside a struct and initialize the values once. They remain untouched and each loop uses its own struct copied from the original in a single assignment statement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2005 08:39 AM
04-05-2005 08:39 AM
Re: Restore c programs data segment to reset globals
save_current_state()) to store the state (i.e current
values of all the global variables) into a file (in binary
format). Write another routine, say
load_saved_state(), and read the saved binary file
exactly the way you stored. This is a simple technique
that should work fine. You could even define a new
large data structure with each field storing one of the
global variable and write/read the data structure in
one fwrite()/fread() call. You could name the states
and store/retrieve multiple states etc. etc..
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2005 08:47 AM
04-05-2005 08:47 AM
Re: Restore c programs data segment to reset globals
you want to save/restore the state of the program
from one instance to another (like, if it gets killed and
restarts with the previous state restored). If you are
not doing that, then writing to / reading from file is not
a good idea (slow disk read/write). In that case, you
could follow my last suggestion, but avoid storing in a
file and store in memory itself.
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2005 11:40 PM
04-05-2005 11:40 PM
Re: Restore c programs data segment to reset globals
This project is mature and has had and will have many people working on it, and theres lotes of variables, and I'm sure they will continue to be added, If I had a universal type store and restore, those developers would not have to make any changes, they could just keep using globals, and I would not have to worry about missing any.
Is there something to give me the address of this segment I need, and could I just save the whole segmetn and restore the whole thing,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2005 12:59 AM
04-06-2005 12:59 AM
Re: Restore c programs data segment to reset globals
The text segment is the code, not the variables. The data segment stores the variables.
I'm still not sure I understand what it is you are trying to achieve in the first place mind you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2005 02:15 AM
04-06-2005 02:15 AM
Re: Restore c programs data segment to reset globals
Large projects like yours are a good example why global variables should be used sparingly because there can be all sorts of side effects. Again, the least evil solution to your situation that I can conceive of is to gather all your globals inside a struct (and yes that means code changes though even if this were 50 files, I think I could do it easily in a day).