[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: saving, restoring prolog state in binary form
From: |
Salvador Abreu |
Subject: |
Re: saving, restoring prolog state in binary form |
Date: |
Thu, 10 Jun 2004 12:44:04 +0100 |
> When we use listing, we are converting the predicates from their "in
> memory representation" into a text form. We then compile these text
> form predicates and load them back into the same "in memory
> representation" next time. (Please correct me if I am missing
> something.)
No, in fact when you use listing/1 you're referring only to "asserted"
predicates, which is one of the three possible internal representations
for code in gprolog: interpreted WAM byte-codes.
When you're compiling a .pl files into a .o file (externally, with
gplc), you translate it into a piece of native code which has little
load-time overhead when included in an executable.
Take for example:
| ?- tell('foo.pl'),
for(I,1,10000),
new_atom(A),
portray_clause(foo(I, f(A))), nl, fail
; told.
(14880 ms) yes
| ?-
Will create a file "foo.pl" in the current directory which looks like
this (first few lines):
foo(1, f(atom_jU6)).
foo(2, f(atom__b8)).
foo(3, f(atom_IjA)).
foo(4, f(atom_cqC)).
....
foo(9999, f(atom_mbC)).
foo(10000, f(atom_w4)).
You can compile it with:
12:26:29$ GLOBALSZ=$[512*1024] gplc -c foo.pl
# GLOBALSZ very large because of the significant number of clauses (10K)
12:27:09$ gplc -o foo foo.o
12:27:56$ ll -g foo*
-rwxr-xr-x 1 spa 2.6M 2004-06-10 12:27 foo
-rw-r--r-- 1 spa 2.9M 2004-06-10 12:27 foo.o
-rw-r--r-- 1 spa 235K 2004-06-10 12:22 foo.pl
"foo" is now a gprolog executable (with the top-level and all) which includes
the foo/2 predicate which was previously generated.
> My application has a few tens of thousands of predicates. So these
> timings become significant.
Try this approach (using gplc to make an executable with all static
predicates).
--
../salvador