How does the hardware manage to save the current workspace state so efficiently? Basically, how does the system save every state in the workspace (windows, desktops, open programs etc) when you do a restart ? Does that affect the efficiency of the software in the long run ?

For example, when I do a restart in windows I know that the laptop restarts completely. Resetting the hardware/software states etc. However, a restart on the macbook pro is like a hibernation in windows, how do they do that ? Is the power to the RAM not cut in the restart process ?

EDIT

There seems to be a clash in responses down there .. Is the image cleared on reboot or not ?
When you restart a Mac it is the same as restarting a Windows machine as far as clearing out the contents of RAM. The difference is when you log in the state of all of the running apps is saved when they quit so they open to the same place they were. This is dependent on how well the application is written. Apps where less attention was paid to saving state don't come back to exactly where they were. Apple apps are very good at this so it appears as if they were never quit.