FunctionPackage: exclToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 10.1
Unrevised from 10.0 to 10.1.
10.0 version

gc-before-c-hooks

Arguments:

Returns a list whose entries each represent a C (or C-compatible) function to call before garbage collections of any kind. The typical declaration of the C function can be

int mybeforehook(int gctype);

where gctype is passed in as 0 if the current gc is a scavenge and 1 if a global-gc.

The list entry itself is typically an (unsigned-byte 32) array, for 32-bit Lisps, or (unsigned-byte 64) or (signed-byte 64) array, for 64-bit Lisps. The array must have at least 1 entry, and its first entry must be the address of the C function. (signed-byte 32) will also work on 32-bit Lisps if the address is small enough or wrapped, if in the upper half of memory. There is no restriction on using a (signed-byte 64) array on a 64-bit Lisp.

setf can be used to store into the list.

A typical usage of this feature is

;;  This example is for 32-bit Lisps as it uses (unsigned-byte 32)
;;  arrays. For 64-bit Lisps, you can use (unsigned-byte 64) arrays
(let ((myaddr (ff:get-entry-point "mybeforehook")))
 (push (make-array 1 :element-type '(unsigned-byte 32)

:initial-element myaddr)
 (excl:gc-before-c-hooks)))

No gc hooks are saved across dumplisps. All applications are responsible for re-establishing their own gc-before-c-hooks.

See also gc.htm for general information on garbage collection in Allegro CL.

Warning: No before hook should ever call back into lisp. The fact that during the hook call a gc is about to begin means that most likely there is no space in lisp heap. Also, it should never be assumed that the callback will not require lisp heap, even if the lisp function itself does not cons. A program whose before-hook calls into lisp may not fail the majority of the time, but it is likely to fail at some inopportune time with disastrous results.


Copyright (c) 1998-2022, Franz Inc. Lafayette, CA., USA. All rights reserved.
This page was not revised from the 10.0 page.
Created 2019.8.20.

ToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 10.1
Unrevised from 10.0 to 10.1.
10.0 version