This is the mail archive of the
guile@cygnus.com
mailing list for the Guile project.
Re: Something like vector-grow available?
Michael Livshin <cmm@verisity.com> writes:
> Jost Boekemeier wrote:
> > I need it to dynamically grow the weak observer array. Maybe I could
> > (ab-)use a weak hash table to hold the weak observers with the key
> > being the observer and the value always being #f.
>
> why a vector at all? so you can use the vector indices to access
> observers?
Jim's idea is that c/scheme/weak observers should be accessed
uniquely. What I have is a list of c structures containing c/scheme
observers where the c observer may be a function that calls the scheme
observer.
struct observer {c_observer_type c; SCM scheme_observer} *observer_list;
The real problem is that some of the scheme_observers may be weak. If
I just don't tag them I can't tell if a weak scheme observer has been
gc'ed. So I store a weak_observer into a weak vector and keep the index
in scheme_observer so that the C observer can retrieve it if
necessary.
Whenever a c() observer is called it must check if the entry in
the weak vector (index stored in scheme_observer) has been gc'ed
and if so it must remove the node from observer_list: This observer
is gone.
Right now I am using a weak hash table to access the weak observers and
fake a key object for each weak_observer. (Yes, it's brain damaged :>
but I needed a weak vector that grows and shrinks).
> ah. this certainly is possible, look at libguile/guardians.h.
Ah, yes. Thank you!
I'll have to go through the list to check if one of my (not marked)
scheme_observers has been zombified befor calling a scheme_observer.
This helps. But what I really need would be a simple notification (a
callback) directly from the garbage collector telling me that this
object will (or has been) removed.
Jost