Next: Library Collections and MzLib Up: Support Facilities Previous: Dynamic Extensions

# Saving and Restoring Program Images

An image is a memory dump from a running MzScheme program that can be later restored (one or more times) to continue running the program from the point of the dump. Images are only supported for statically-linked Unix versions of MzScheme (and MrEd). There are a few special restrictions on images:

- All files and TCP connections must be closed when an image is created.
- No dynamic extensions can be loaded before an image is created.
- No operating system subprocesses can be active when an image is created.

`(write-image-to-file file-path [cont-proc])` copies the state of the entire MzScheme process to file-path, replacing file-path if it already exists. If images are not supported, the `exn:misc:unsupported` exception is raised. If cont-proc is `#f`, then the MzScheme or MrEd process exits immediately after creating the image. Otherwise, cont-proc must be a procedure of no arguments, and the return value(s) of the call to `write-image-to-file` is `(cont-proc)`. The default value for cont-proc is `void`.

`(read-image-from-file file-path arg-vector)` restores the image saved to file-path. Once the image is restored, execution of the original program continues with the return from `write-image-to-file`; the return value in the restored program is the a vector of strings arg-vector. A successful call to `read-image-from-file` never returns because the restored program is overlayed over the current program. The vector arg-vector must contain no more than 20 strings, and the total length of the strings must be no more than 2048 characters.

If an error is encountered while reading or writing an image, the `exn:i/o:filesystem` exception is raised or `exn:misc` exception is raised. Certain errors during `read-image-from-file` are unrecoverable; in case of such errors, MzScheme prints an error message and exits immediately.

An image can also be restored by starting the stand-alone version of MzScheme or MrEd with the `--restore` flag followed by the image filename. The return value from `write-image-to-file` in the restored program is a vector of strings that are the extra arguments provided on the command line after the image filename (if any).

Next: Library Collections and MzLib Up: Support Facilities Previous: Dynamic Extensions