- Documentation
- Reference manual
- Foreign Language Interface
- The Foreign Include File
- Argument Passing and Control
- Atoms and functors
- Analysing Terms via the Foreign Interface
- Constructing Terms
- Unifying data
- Convenient functions to generate Prolog exceptions
- Serializing and deserializing Prolog terms
- BLOBS: Using atoms to store arbitrary binary data
- Exchanging GMP numbers
- Calling Prolog from C
- Discarding Data
- String buffering
- Foreign Code and Modules
- Prolog exceptions in foreign code
- Catching Signals (Software Interrupts)
- Miscellaneous
- Errors and warnings
- Environment Control from Foreign Code
- Querying Prolog
- Registering Foreign Predicates
- Foreign Code Hooks
- Storing foreign data
- Embedding SWI-Prolog in other applications
- The Foreign Include File
- Foreign Language Interface
- Packages
- Reference manual
The second group (headed by PL_record_external()) provides the same functionality, but the returned data has properties that enable storing the data on an external device. It has been designed for fast and compact storage of Prolog terms in an external database. Here are the main features:
- Independent of session
Records can be communicated to another Prolog session and made visible using PL_recorded_external(). - Binary
The representation is binary for maximum performance. The returned data may contain zero bytes. - Byte-order independent
The representation can be transferred between machines with different byte order. - No alignment restrictions
There are no memory alignment restrictions and copies of the record can thus be moved freely. For example, it is possible to use this representation to exchange terms using shared memory between different Prolog processes. - Compact
It is assumed that a smaller memory footprint will eventually outperform slightly faster representations. - Stable
The format is designed for future enhancements without breaking compatibility with older records.
- char * PL_record_external(term_t +t, size_t *len)
- Record the term t into the Prolog database as recorda/3
and return an opaque handle to the term. The returned handle remains
valid until PL_erase_external()
is called on it. Currently aborts the process with a fatal error
on failure. Future versions may raise a resource exception and return
(record_t)0
.It is allowed to copy the data and use PL_recorded_external() on the copy. The user is responsible for the memory management of the copy. After copying, the original may be discarded using PL_erase_external().
PL_recorded_external() is used to copy such recorded terms back to the Prolog stack.
- int PL_recorded_external(const char *record, term_t -t)
- Copy a recorded term back to the Prolog stack. The same record may be used to copy multiple instances at any time to the Prolog stack. See also PL_record_external() and PL_erase_external().
- int PL_erase_external(char *record)
- Remove the recorded term from the Prolog database, reclaiming all associated memory resources.
12.4.17.3 Database
- int PL_assert(term_t t, module_t m, int flags)
- Provides direct access to asserta/1
and assertz/1
by asserting t into the database in the module m.
Defined flags are:
- PL_ASSERTZ
- Add the new clause as last. Calls assertz/1. This macros is defined as 0 and thus the default.
- PL_ASSERTA
- Add the new clause as first. Calls asserta/1.
- PL_CREATE_THREAD_LOCAL
- If the predicate is not defined, create it as thread-local. See thread_local/1.
- PL_CREATE_INCREMENTAL
- If the predicate is not defined, create it as incremental see table/1 and section 7.7.
On success this function returns
TRUE
. On failureFALSE
is returned and an exception is left in the environment that describes the reason of failure. See PL_exception().This predicate bypasses creating a Prolog callback environment and is faster than setting up a call to assertz