Variable | Package: excl | ToC | DocOverview | CGDoc | RelNotes | FAQ | Index | PermutedIndex
| Allegro CL version 9.0 Unrevised from 8.2 to 9.0. 8.2 version

## *gc-after-hook*

If the gsgc switch `:hook-after-gc` is true, then the value of this symbol, if true, will be funcall'ed immediately after a scavenge. Thus the value should be a function that takes five arguments:

1. a boolean which will be true if the gc just completed was a global gc,
2. a fixnum equal to the number of bytes copied to newspace,
3. a fixnum equal to the number of bytes copied to oldspace,
4. a fixnum which is the efficiency as a percentage (see Note 1 just below),
5. and a fixnum which is the number of bytes that still must be allocated (see Note 2 just below).

Note 1: Efficiency is the ratio of non-gc cpu time to total cpu time.

Note 2: Garbage collections usually happen because an object must be allocated but there is not enough free space to do so. The fifth argument gives the size of not-yet-allocated objects.

Because the amount of free space needed (as specified by the last returned value) must be available, modifying the amount of free space in newspace as a side effect of executing `*gc-after-hook*` code is dangerous. Lisp can fail if there is in fact inadequate free space to allocate the object whose allocation triggered the gc. This means the code should not cons (or should minimally cons) and should not reduce the size of newspace with, for example, a call to resize-areas. While there may be cases where a carefully coded call to resize-areas in a gc after hook is appropriate, the rule of thumb is do not call that function.

The initial value of this variable is a function that implements the global gc behavior described in Global garbage collection in gc.htm and in the description of `*global-gc-behavior*`. The function is named by the internal symbol `excl::default-gc-after-hook`. If you wish to change the value of this variable and preserve the global gc behavior described below, set the value of this switch to something like the following (note the use of a feature to prevent recursion if this code is run twice):

    ;; This form should be placed in a location (such as a file)
    ;; where it can be compiled.
    ;; The inital value of excl:*gc-after-hook* is a function named by
    ;; the symbol excl::default-gc-after-hook but we bind the value
    ;; to allow for an already modified function whose behavior
    ;; is being preserved.
    (let ((continuation excl:*gc-after-hook*))
      (if (null (excl:featurep :my-gc-after-hook-added))
          (progn
            (push :my-gc-after-hook-added *features*)
            (setq excl:*gc-after-hook*
                #'(lambda (global new old efficiency to-be-allocated)
                    ; ... code to do what you want after a gc ....
                    (when continuation
                      (funcall continuation global
                               new old efficiency to-be-allocated))
                       ; ... more of your code if desired
                       )
           ))))

See also gc.htm for general information on garbage collection Allegro CL, including information on gsgc switches and parameters. See section Global garbage collection in that document for information on global garbage collection.

Copyright (c) 1998-2019, Franz Inc. Oakland, CA., USA. All rights reserved.
This page was not revised from the 8.2 page.
Created 2012.5.30.

|  | ToC | DocOverview | CGDoc | RelNotes | FAQ | Index | PermutedIndex
| Allegro CL version 9.0 Unrevised from 8.2 to 9.0. 8.2 version