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: Thomas Chust
Subject: Re: [Chicken-users] Returning a scheme object inside another
Date: Wed, 23 Nov 2005 11:30:35 -0000
User-agent: Opera M2/8.02 (MacPPC, build 2148)

Am 23.11.2005, 04:39 Uhr, schrieb Zbigniew <address@hidden>:

I have a C function which calls another C function that creates and
returns a scheme-object.  Because it returns (rather than continuing)
I cannot allocate this on the stack, rather I use malloc.  The
original caller itself returns this object, along with a c-pointer
that can later be freed.  As the return value is copied, this works
fine.
[...]

Hello,

whether all of them are good I don't know, but there are some alternatives
that come to my mind:
  - use CPS throughout your C code directly
  - allocate space on the stack in the outer C procedure and
    pass a pointer to it to the inner one
  - in the outer C function, copy the heap allocated data returned from the
    inner function into the stack, then continue into Scheme, which will
    copy the stuff back into garbage collected heap (doesn't sound very
    efficient, but should work)
  - in the inner C function, force the stuff into the garbage collected
    heap. Maybe CHICKEN's object-copy function could be used for this
    somehow.

By the way, could someone perhaps explain me what exactly C_mutate does?
I played around with it a little and found that I have apparently totally
misunderstood the documentation -- I thought that it would cause stack
allocated objects to be copied into heap when the mutated slot was in the
heap itself.

cu,
Thomas




reply via email to

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