How do I save the memory state of a C program so I can jumpstart later

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jim McCarter
    New Member
    • Jul 2010
    • 1

    How do I save the memory state of a C program so I can jumpstart later

    In a large complex C program, I wish to save - to a file - the contents of all memory that is used by static variables, global structures and dynamically allocated variables. Then, in a separate execution of the program, I want to initialize the memory from this saved state. If this is even possible, can someone offer an approach to accomplish this? This has to do with jump-starting a trajectory simulation from a previously saved state.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    I am not aware of any generic approach to this. Remember you would not just need the state of all variables but the run state of all threads.

    I am not saying it can't be done just that any solution is likely to be application specific and probably needs to be designed in from the ground up.

    Not having any static/global data and allocating everything from the heap may help. The reason being you can intercept heap allocations which gives you easy access to the data for saving program state by having a central repository for all data.

    Additionally while you are saving you will need to ensure all threads are halted. It will do no good to save program state if between the start and the end of the save 1 or more threads alter some of the data.

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Are you able to make a system call for a context switch?

      Whenever you change threads, the OS has to save the state of the machine so the new thread can't screw up the old thread.

      Comment

      Working...