[gambit-list] Getting char*, uchar*, short*, unsigned short*, ... out of a uvector

Marc Feeley feeley at iro.umontreal.ca
Fri Apr 17 00:30:35 EDT 2009


On 17-Apr-09, at 12:19 AM, lowly coder wrote:

> Hi!
>
>   This is a different question from my previous silly question.
>
>   All though it's really cool that I can take a C function with  
> signature:
> void foo(int *);
>   and in scheme land create a (scheme-foo) so that I can do:
>
>   (define bar (make-u....vector ...))
>   (scheme-foo bar)
>
>   There are a lot of C functions I need to use that take arguments  
> int*, short*, ...
>
>   I would prefer to not change all these C bindings, and somehow  
> magically have a Scheme function that given:
>   (uber-magic bar)
>   returns me a int* corresponding to where the data is stored in u32- 
> vector bar.

That would be problematic because objects in the Scheme heap,  
including vectors, can be moved by the garbage collector.  So a C  
pointer to an element of a u32vector could become stale (dangling  
pointer) at any moment.  The only way this could work is to allocate a  
"still" vector.  But all of this is seriously asking for trouble (the  
pointer will be a dangling pointer when the still object is reclaimed).

Marc




More information about the Gambit-list mailing list