chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] "closing" pointers returned by C when they are not n


From: felix
Subject: Re: [Chicken-users] "closing" pointers returned by C when they are not needed
Date: Tue, 11 May 2004 00:41:19 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040113

Alejandro Forero Cuervo wrote:

How can I let the GC code know that it should call iconv_close(3)
when the C-pointer (returned by foreign-lambda* in iconv-open) is
no longer required?


What you can do is use finalizers. The procedure

(set-finalizer! OBJECT PROC)

will call PROC, once the OBJECT (which may for example be a
foreign pointer object) is reclaimed by the garbage collector.

But: using many fimalizers can be somewhat inefficient, the algorithm
for interning new items in the internal finalizer list is not very
clever (and has to improve).

And: finalizers can be tricky to use. If the pointer is reclaimed,
the data it points to may still be used by C code. So be very
careful when using them.


cheers,
felix




reply via email to

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