Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Windows Hibernation works

Tags:

.net

windows

Out of curiosity, I was looking for an article/documentation on "how windows hibernate option work", i.e. when one selects "Hibernate" option in windows shutdown dialog. The reply I got from some sources was that, its mere serialization of memory and registers.

Pardon me if I am wrong here. If windows could serialize any applications, process or objects regardless of whether its serializable or non-serializable, how come .NET limits serializable objects to those with [Serializable] attribute or ISerializable interface?

like image 824
AbrahamJP Avatar asked Mar 06 '11 10:03

AbrahamJP


1 Answers

Inside a process address-space, everything is just bytes; some stack, some managed heap, etc. Bytes are inherently serializable - they are just bytes. All hibernate has to do is suspend the threads and write the entire address space to disk.

With objects, you want to save them to some out-of-memory structure. Unfortunately, it makes no sense to store addresses etc, as it is exceptionally unlikely to rehydrate into exactly the same point in memory. Additionally, many things like unmanaged object handles will make no sense when rehydrated. It is also extremely likely that you want to save just a small block of objects, not an entire process space. And even in a small graph, those objects could be scattered all over the place - so you can't just copy out a few pages of memory.

Also keep in mind that a common use of serialization is to deep-clone objects; if you relied on the in-memory representation of objects, you would have to deserialize to exactly the same place in memory - so you can't have cloned anything. And that is *before you touch on concepts such as compacting garbage collectors, which move objects around in memory while you aren't looking.

Also consider that you might be loading the data into a different platform / architecture, or want to write a specific format (xml, json, etc).

So instead of just copying raw memory, serialization code must look at individual objects, traversing references and writing an object graph in a way that allows rehydration from a source that has nothing at all to do with raw memory. Much harder.

like image 52
Marc Gravell Avatar answered Sep 28 '22 01:09

Marc Gravell