Implemented saving and loading of memstate.

The implementation is extremely hackish, but this should be good enough for
testing.  For now, at least.