[Contents]   [Back]   [Prev]   [Up]   [Next]   [Forward]  


guardians

Status: useful, does the concept as well as the mechanism

Description: guardians are another in the long line of powerful abstractions that scheme embraces. Their essential purpose it to provide a powerful finalization mechanism for dead objects. How this works is that you create a guardian G. For every object that you want to be protected, you do a (G obj). Now, after a garbage collection, you can retrieve each of the objects that were not traced (and therefore dead) by doing (G). An example:

(define G (make-guardian))
(G (cons 'a 'b))
;;; Notice the only reference to that cons is in G
(gc)
(G)
=> (a . b)

(G)
=> #f

This provides us with a very flexible and garbage collector independant way of doing object finalization.

Note: the definitive reference for guardians is at ftp://ftp.cs.indiana.edu/pub/scheme-repository/doc/pubs/guardians.ps.gz The implementation is much the same as with the guile version.

Note: there's no particular special treatment given to a guardian object itself. It won't hang around if there's no reference to it, and it'll take all of your objects with it.

Note: the underlying structures holding the objects are called tconc's, which is a bizarre lisp way of saying "queue implemented with a cons cell, where the car points to a list, and the cdr points to the tail of the list".

Note: the guardian itself is actually just a cclo, which contains a slot for the guardian itself, and dispatches on either scm_guard or scm_get_one_zombie. (an interesting thing I noticed is that a cclo appears to use the values of it's slots for optional arguments, but don't quote me on that, 'cause I'm not quite sure if that's entirely accurate).

Function: make-guardian
C Function: SCM scm_make_guardian (void)
Returns a brand new guardian object.
C Function: void scm_guardian_gc_init (void)
Initializes the guardians for garbage collection. Only called from the gc.

C Function: void scm_guardian_zombify (void)
This is the function which moves the dead guardians into their own special place. Called from scm_igc.
C Function: void scm_guard (SCM guardian, SCM obj)
This is the c function you can call to add an object to the guardian.

C Function: SCM scm_get_one_zombie (SCM guardian)
Retrieves one zombie object from guardian.

Internal C Function: static SCM guard (SCM cclo, SCM arg)
This is the main dispatch function, which calls either scm_guard if arg is given, or scm_get_one_zombie if arg is undefined.


[Contents]   [Back]   [Prev]   [Up]   [Next]   [Forward]