For various specific applications some hooks are provided.
PL_DISPATCH_INPUT
indicates Prolog input is available on
file descriptor 0 or PL_DISPATCH_TIMEOUT
to indicate a
timeout. The old hook is returned. The type PL_dispatch_hook_t
is defined as:
typedef int (*PL_dispatch_hook_t)(void);
PL_abort_hook_t
is defined as:
typedef void (*PL_abort_hook_t)(void);
FALSE
if no such hook is found, TRUE
otherwise.NULL
is returned. The
argument of the called hook is the atom that is to be garbage collected.
The return value is an int
. If the return value is zero,
the atom is not reclaimed. The hook may invoke any Prolog
predicate.
The example below defines a foreign library for printing the garbage collected atoms for debugging purposes.
#include <SWI-Stream.h> #include <SWI-Prolog.h> static int atom_hook(atom_t a) { Sdprintf("AGC: deleting %s\n", PL_atom_chars(a)); return TRUE; } static PL_agc_hook_t old; install_t install() { old = PL_agc_hook(atom_hook); } install_t uninstall() { PL_agc_hook(old); }