There are three areas that require special attention when using
qsave_program/[1,2].
- If the program is an embedded Prolog application or uses the foreign
language interface, care has to be taken to restore the appropriate
foreign context. See section
14.2.3 for details.
- If the program uses directives (
:- goal. lines) that
perform other actions than setting predicate attributes (dynamic/1, volatile/1,
etc.) or loading files (use_module/1,
etc.). Goals that need to be executed when the state is started must use initialization/1
(ISO standard) or initialization/2
(SWI extension that provides more control over when the goal is
executed). For example, initialization/2
can be used to start the application:
:- initialization(go, main).
- Blobs used as references to the database (see clause/3,
recorded/3),
streams, threads, etc. can not be saved. This implies that (dynamic)
clauses may not contain such references at the moment the
qsave_program/2
is called. Note that the required foreign context (stream, etc.) cannot
be present in the state anyway, making it pointless to save such
references. An attempt to save such objects results in a warning.
The volatile/1
directive may be used to prevent saving the clauses of predicates that
hold such references. The saved program must reinitialise such
references using the normal program initialization techniques: use initialization/1,2
directives, explicitly create them by the entry point or make the
various components recreate the context lazily when required.
- Blobs that properly implement the save()
and load()
callbacks can be saved and restored. By default a blob is saved as an
array of bytes, of the internal form of the blob. This means that any
saved program using such a blob is probably not portable to a different
architecture.