- 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
es or significant memory resources
it may be desirable to have an explicit call to dispose (most of) the
resources. For example,
close/1
reclaims the file handle and most of the resources associated with a
stream, leaving only a tiny bit of content to the garbage collector. See
also setup_call_cleanup/3.
int compare(atom_t
a, atom_t b) Compare the blobs a and b, both of which are of
the type associated to this blob type. Return values are as memcmp(): <
0 if
a is less than b, = 0 if both are
equal, and > 0 otherwise. The default implementation is a
bitwise comparison of the blobs' contents. If you cannot guarantee that
the blobs all have unique contents, then you should incorporate the blob
address (the system guarantees that blobs are not shifted in memory
after they are allocated). The following minimal compare function gives
a stable total ordering:
int write(IOSTREAM
*s, atom_t a, int flags) Write the content of the blob a to the stream s
respecting the flags. The flags are a bitwise
or of zero or more of the
static int compare_my_blob(atom_t a, atom_t b) { const struct my_blob_data *blob_a = PL_blob_data(a, NULL, NULL); const struct my_blob_data *blob_b = PL_blob_data(b, NULL, NULL); return (blob_a > blob_b) ? 1 : (blob_a < blob_b) ? -1 : 0; }
PL_WRT_*
flags defined
in
SWI-Prolog.h
. This prototype is available if the
undocumented SWI-Stream.h
is included before
SWI-Prolog.h
. This function can retrieve the data of the
blob using PL_blob_data().
If this function is not provided, write/1
emits the content of the blob for blobs of type PL_BLOB_TEXT
or a string of the format <#
hex data>
for binary blobs.
If a blob type is registered from a loadable object (shared object or DLL) the blob type must be deregistered before the object may be released.
- int PL_unregister_blob_type(PL_blob_t *type)
- Unlink the blob type from the registered type and transform the type of
possible living blobs to
unregistered
, avoiding further reference to the type structure, functions referred by it, as well as the data. This function returnsTRUE
if no blobs of this type existed andFALSE
otherwise. PL_unregister_blob_type() is intended for the uninstall() hook of foreign modules, avoiding further references to the module.
12.4.9.2 Accessing blobs
The blob access functions are similar to the atom accessing functions. Blobs being atoms, the atom functions operate on blobs and vice versa. For clar