Persist (hibernate!) a process state to disk for quiker loading


  • Is there any straight forward way to Persist (hibernate!) a process state (C++/C# window exe) to disk so that it can be quickly loaded later when required?


    ~ Pervez

    Wednesday, March 28, 2012 2:27 PM

All replies

  • One way would be to make EVERYTHING in your software serializable:

    (and I like)

    Then you can dump and load the objects with relative ease...I don't think there is a mechanism like hibernate though.

    Wednesday, March 28, 2012 2:41 PM
  • Thanks Hat. Our legacy app is C++ only, though it has some C# modules as well. But most of the modules are in C++ only. Above approach will not work for such apps, right?

    Wednesday, March 28, 2012 2:55 PM
  • Oh sorry, I mixed up the forums. You are right...there is no native C++ serialize (there is in C++/CLI though), you'd have to write such a mechanism yourself. If you can change the legacy app, than you could implement your own serializeable interface (a "ToXML" function would work nicely) BUT it would probably end up being a ton of work.

    If you are using C# wrappers around your C++ code, you could still implement the serialize attribute on the wrapper classes, but this would probably be hard to get a non-shallow implementation...

    Wednesday, March 28, 2012 3:09 PM
  • Just force the app to swap out, and its state will be nicely preserved in the system page file.  Windows also has prefetch feature to accelerate load time. It has been well tested and optimized.

    Before rolling your own and reinventing the wheel, it's worth to learn the optioipns at hand. Investing in a fast disk for the pagefile will help too.

    -- pa

    Wednesday, March 28, 2012 4:19 PM
  • Thanks Pavel for the update. Can you please explain more on how this swap works so that process state will be saved in disk and reuse when required? Prefetch feature was already enabled in my system, but still application loading takes time.
    Wednesday, March 28, 2012 4:41 PM
  • Can you please explain more on how this swap works so that process state will be saved in disk and reuse when required?

    It's very simple. The Page file is a special place on a disk where inactive processes are stored in highly optimized way. When such process resumes running, the system automagically reads it back to memory and it just continues from where it was. It is sort of how programs run on iPad :)

    All this functionality is already built into Windows. While your process keeps running, the system ensures that it is either in the memory or in the page file (there are few exceptons though, which you can ignore).

    Hope this helps,

    -- pa

    Wednesday, March 28, 2012 8:43 PM
  • Thanks Pavel for the reply. My question was more around code point of view - How to persist the process state of a big legacy c++ app to disk while closing it for quicker loading..?
    Thursday, March 29, 2012 5:30 AM
  • I don't think you can persist process information. In .NET the data in class can be serialization and de-serialization. As Pavel said, this is system function, you can not control it using codes. 


    Friday, March 30, 2012 5:35 AM