[Chicken-users] assigning scheme object to foreign pointer
Hello everybody. 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. Is there another way to accomplish this, maybe by telling the gc not to move the object? thank you very much in advance, Pluijzer ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] assigning scheme object to foreign pointer
On 2013-12-16 00: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. [...] Hello, check out CHICKEN_new_gc_root and friends [1]. These functions can be used to manage mutable cells that can hold references to Scheme objects and are taken into account by the garbage collector. Ciao, Thomas -- [1] http://wiki.call-cc.org/man/4/Embedding#chicken_new_gc_root -- When C++ is your hammer, every problem looks like your thumb. ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] assigning scheme object to foreign pointer
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 ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] assigning scheme object to foreign pointer
Hello Evan and Thomas, Thank you for your suggestions, I decided to go for `CHICKEN_new_gc_root` and it works like I hoped. I was the lookup-table before but found it to be too unwieldy in my project. Thanks again, Pluijzer On Mon, 16 Dec 2013 13:28:27 +1300 Evan Hanson ev...@foldling.org wrote: 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 ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users -- pluijzer pluij...@gmail.com ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users