[Up] [Contents] [Index] [Summary]

2.9.2 Save Predicates

save_program(+NewProgram, +ListOfOptions)
Create a new executable which will be named NewProgram. ListOfOptions is a list of Key = Value pairs that specify the default command line options that will be saved into the new program. If a default is not specified the default compiled into the currently running Prolog executable is used. (8) The available keys are given in table 2

KeyOptionTypeDescription
local-LK-bytesSize (Limit) of local stack
global-GK-bytesSize (Limit) of global stack
trail-TK-bytesSize (Limit) of trail stack
argument-AK-bytesSize (Limit) of argument stack
goal-gatomInitialisation goal
toplevel-tatomProlog toplevel goal
init_file-fatomPersonal initialisation file
tty+/--ttyon/offUse ioctl(2) calls

Table 2 : Key = Value pairs for save_program/2

As the entire data image of the current process will be saved on the new executable it is desirable to keep this small. Notably the Prolog machine stacks should be kept small. The best way to do this is first to compile the program using the -c option. If this is not possible try to find the smallest possible stack sizes to compile the program. On machines with dynamic stack allocation the stacks are not written to file and so their size does not matter. Figure 4 shows a possible session. Note the use of `initialise', which is supposed to be a predicate of the application doing time consuming initialisation.

sun% pl -c load foreign file dbase loaded 0.066667 seconds, 1578 bytes. setup consulted, 0.500000 seconds, 5091 bytes. main consulted, 0.333333 seconds, 3352 bytes. load consulted, 1.000000 seconds, 9867 bytes. sun% a.out -f none -L10 -G10 -T5 foreign file dbase loaded 0.066667 seconds, 1578 bytes. Welcome to SWI-Prolog (Version \plversion) Copyright (c) 1993-1996 University of Amsterdam. All rights reserved. For help, use ?- help(Topic). or ?- apropos(Word). 1 ?- initialise. Yes 2 ?- save_program(my_program, [ local = 500 , goal = go , init_file = none ]). Running executable: /usr/local/bin/pl Saving to my_program; text: 204800 ... data: 357000 ... symbols ... done. Yes 2 ?- halt. sun%

Figure 4 : Create a stand-alone executable

The resulting program can be used for incremental compilation using -c or another save_program/2.

save_program(+NewProgram)
Equivalent to `save_program(NewProgram, [])'.

save(+State)
Writes the current status on the program, Prolog- and C-stacks to the file State. When this file is restored, save/1 succeeds in the restored state and execution continues as illustrated by the following example:

1 ?- save(state), format('Hello World~n'). Hello World Yes 2 ?- halt. machine% ./state Hello World Yes 2 ?- h. 1 save(state), format('Hello World~n'). 2 ?-

The save/1 predicate is normally used for debugging purposes. save_program/[1,2] is the preferred way to create a new program.

save(+State, -Rval)
Like save/1, but unifies Rval with 0 when save/2 returns from a real save and with 1 when save/2 returns from a restore.

restore(+State)
Equivalent to restarting State.