SWI-Prolog's heap memory allocation is based on the malloc(3) library routines. SWI-Prolog provides the functions below as a wrapper around malloc(). Allocation errors in these functions trap SWI-Prolog's fatal-error handler, in which case PL_malloc() or PL_realloc() do not return.
Portable applications must use PL_free()
to release strings returned by PL_get_chars()
using the BUF_MALLOC
argument. Portable applications may
use both PL_malloc()
and friends or malloc() and friends but should not mix these two
sets of functions on the same memory.