4.17.6 Fast binary term I/O
The predicates in this section provide fast binary I/O of arbitrary
Prolog terms, including cyclic terms and terms holding attributed
variables. Library library(fastrw)
is a SICSTus/Ciao
compatible library that extends the core primitives described below.
The binary representation the same as used by PL_record_external(). The use of these primitives instead of using write_canonical/2 has advantages and disadvantages. Below are the main considerations:
- Using write_canonical/2 allows or exchange of terms with other Prolog systems. The format is stable and, as it is text based, it can be inspected and corrected.
- Using the binary format improves the performance roughly 3 times.
- The size of both representations is comparable.
- The binary format can deal with cycles, sharing and attributes. Special precautions are needed to transfer such terms using write_canonical/2. See term_factorized/3 and copy_term/3.
- In the current version, reading the binary format has only incomplete consistency checks. This implies a user must be able to trust the source as crafted messages may compromise the reading Prolog system.
- fast_term_serialized(?Term, ?String)
- (De-)serialize Term to/from String.
- fast_write(+Output, +Term)
- Write Term using the fast serialization format to the Output stream. Output must be a binary stream.
- fast_read(+Input, -Term)
- Read Term using the fast serialization format from the Input stream. Input must be a binary stream.bugThe predicate fast_read/2 may crash on arbitrary input.