chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] assigning scheme object to foreign pointer


From: Evan Hanson
Subject: Re: [Chicken-users] assigning scheme object to foreign pointer
Date: Mon, 16 Dec 2013 13:28:27 +1300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131103 Firefox/17.0 Icedove/17.0.10

Hi Pluijzer,

On 16/12/13 12:59, pluijzer wrote:
> I am using a C-library that lets you assign user data to objects via a
> void pointer. I would like to assign a scheme object to this pointer,
> but as I understand I cannot use 'object->pointer' for this, as the
> garbage collector might move the object.

There are a couple of ways to do this.

One is to manually move the object into static memory, via
`object-evict` (http://api.call-cc.org/doc/lolevel#def:object-evict).
This is nice and easy, but might not work as expected for all data
types.

Another is to create a new GC root for the object, via
`CHICKEN_new_gc_root` and its associated procedures
(http://api.call-cc.org/doc/foreign/embedding#sec:CHICKEN_new_gc_root).

You might also sidestep the issue entirely by keeping your objects in a
Scheme-side lookup table and only storing immediate values in the
pointer that you can then use to retrieve the objects as needed.

Other folks may chime in with more ideas, but I hope these help some.

Cheers,

Evan



reply via email to

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