SP_set_memalloc_hooks()
[preinit]#include <sicstus/sicstus.h> typedef int SP_InitAllocHook(size_t alignment, void *cookie); typedef void SP_DeinitAllocHook(void *cookie); typedef void * SP_AllocHook(size_t size, size_t *actual_sizep, void *cookie); typedef int SP_FreeHook(void *ptr, size_t size, int force, void *cookie); int SP_set_memalloc_hooks(int hint, SP_InitAllocHook *init_alloc_hook, SP_DeinitAllocHook *deinit_alloc_hook, SP_AllocHook *alloc_hook, SP_FreeHook *free_hook, void *cookie);
Defines the Prolog memory manager's bottom layer.
Must be called before SP_initialize()
.
alignment
is guaranteed to be a power of 2,
and is used by alloc_hook
. earliest_start
(inclusive) and
latest_end
(exclusive) are the bounds within which
address-constrained memory blocks must fit. Both are aligned according
to alignment
and non-zero. The function can do whatever
initialization that this layer of memory management wants to do. It
should return non-zero if it succeeds, zero if the memory manager bottom
layer could not be initialized, in which case initialization of the
SICStus run-time will fail.
SP_deinitialize()
when the Prolog engine shuts down.
The function can do any necessary cleaning up.
size
bytes aligned at a multiple of alignment
. The
actual size of the piece of memory should be returned in
*actual_sizep
. Should return NULL
if it
cannot allocate a suitable piece of memory. Note that the memory
returned need not be aligned as long as there is room for an aligned
block of at least size
bytes.
alloc_hook
. If force
is non-zero,
free_hook
must accept the piece of memory; otherwise, it only
accepts it if it is able to return it to the operating system.
free_hook
should return non-zero iff it accepts the piece of
memory. Otherwise, the upper layer will keep using the memory as if
it were not freed.
SP_set_memalloc_hooks()
is passed to each
hook function. One possible use is to keep track of multiple
SICStus run-times within the same process.
Non-zero on success, Zero on error, e.g. if called after
SP_initialize()
.
The default bottom layers look at the environment variables PROLOGINITSIZE, PROLOGINCSIZE, PROLOGKEEPSIZE and PROLOGMAXSIZE. They are useful for customizing the default memory manager. If you redefine the bottom layer, you can choose to ignore these environment variables. See too-sicstus.
Initializing the Prolog Engine.