[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: foreign objects and the garbage collector

From: adriano
Subject: Re: foreign objects and the garbage collector
Date: Sun, 19 Sep 2021 08:14:39 +0200

Il giorno sab, 04/09/2021 alle 15.35 +0200, Vivien Kraus via General
Guile related discussions ha scritto:
> Hello,
> Le samedi 04 septembre 2021 à 07:41 -0500, Tim Meehan a écrit :
> > I'd rather not compile anything in C, and just use the tools in
> > Guile to
> > interact with libgps. Is there a way to get Guile's garbage
> > collector to
> > call "gps_close" on the opaque structure returned by "gps_open"?
> I think it would be best to do it yourself. Maybe the garbage
> collector will not run immediately (if at all), and if each creation
> uses "precious" resources (such as file descriptors), you might run
> into a shortage before the garbage collector is triggered. This is
> not considered by people writing the C API of course, because they
> assume you would close the thing as soon as possible. (Also, if
> calling the close function is mandatory, for instance to run code
> that’s not just freeing resources, and the garbage collector does not
> have a chance to run, then it’s another problem. However, I
> doubt your library does something like that). 
> If you want to avoid the problem, you should explicitely bind and
> call the gps-close function and not rely on the garbage collector to
> do it for you. You can use dynamic-wind to open and close
> resources as needed.

It'd be so nice to have an example

> That being said, make-pointer (from (system foreign-library)) is
> probably what you are expecting. It should work with gps_close.

Another exmple of what you mean, here, would be so nice :-)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]