chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] Returning a scheme object inside another


From: felix winkelmann
Subject: Re: [Chicken-users] Returning a scheme object inside another
Date: Wed, 23 Nov 2005 09:35:28 +0100

On 11/23/05, Zbigniew <address@hidden> wrote:
>
> The problem comes when I want to return a scheme-object inside another
> container (such as a list or a structure).  Unfortunately, a slot not
> pointing to the nursery (such as a pointer to a malloced area) is not
> copied into GC-able memory, even when using C_mutate.  [I only tried
> this with a structure, but I think the same will happen with a list.]

This is a feature. :-)

> So, I can never free this pointer, although maybe some trickery with
> finalization would work.

(Probably not, since finalizers don't work for Scheme data allocated
in non-GC'd memory)

> I anticipate though that I might have to return several objects at the
> same time, say in a list.  I would hate to have to allocate them all
> on the heap, but malloc or C_alloc won't work.  I can only think of
> two other solutions: 1) invoke a callback to cons the objects into a
> list, magically copying them into the heap; or 2) rewrite a lot of
> this code into Scheme and have the allocation taken care of for me.
>
> As for #1, the overhead of a foreign-safe-lambda may be annoying in
> this application (I will have to see) and as for #2, I have been
> avoiding it as there are a bunch of nested C functions, and I may not
> be able to wrap some due to idiosyncrasies in the host API.  However,
> this option is growing on me.
>

The "official" way would be to call back into Scheme, allocating
the data on the Scheme side. But callbacks indeed have some
performance penalty.
One possible way might be to allocate the data in a static buffer
(not dynamically) and call `object-copy' on it (to create a heap-allocated
version of the copied data) after the return.


cheers,
felix




reply via email to

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