chicken-users
[Top][All Lists]
Advanced

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

[Chicken-users] Re: foreign-lambda* question


From: John J Foerch
Subject: [Chicken-users] Re: foreign-lambda* question
Date: Thu, 10 Mar 2011 10:53:39 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

Thomas Chust <address@hidden> writes:
>
> Hello John,
>
> looking at your code I have two immediate questions: Why do you
> recompute the length of a list twice, which is a linear operation,
> when you could simply store the length or access the length of the
> vector you create in constant time?
>

Just sloppiness, while I try to get things working.


>> I malloc memory and copy the data into the block, then return the
>> pointer to the block for use in scheme.
>
> And why do you allocate this block at all when you already have a
> u32vector with precisely the same memory layout?
>

On a 64 bit machine, an unsigned long will be 64 bits, and this is what
xlib expects.


>> My question is, what is the idiomatic way in Chicken to free the
>> allocated memory, or turn it over to the garbage collector?
>> [...]
>
> If you really need this block of unmanaged memory for some obscure
> reason, you can either manually free it at some point where it is safe
> to do so, or you can register the free function as a finalizer on the
> foreign pointer object and let the garbage collector invoke it after
> the pointer has gone out of scope from the viewpoint of your CHICKEN
> program. Something like this should do:
>
>   (set-finalizer! YOUR-POINTER (foreign-lambda void "free" c-pointer))
>
> Ciao,
> Thomas


Very nice, thank you.

-- 
John Foerch




reply via email to

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