[plt-scheme] Binding C-Structs Containing Fixed-Size Arrays with the FFI

From: Eli Barzilay (eli at barzilay.org)
Date: Mon Jan 26 16:16:49 EST 2009

On Jan 26, Henk Boom wrote:
> 2009/1/26 Eli Barzilay <eli at barzilay.org>:
> >
> > At the scheme side -- as long as you're doing the allocations --
> > there shouldn't be any problems since it's all handeled
> > transparently by the GC.
> 
> I'm just worried because the cvector returned by (foo-j s) points to
> the middle of the structure, not to the beginning, and I'm not sure
> if the garbage collector can keep track of it.

Ah, I missed that.  No, this is forbidden: the GC won't know about it,
so it will move the block leaving you with most likely invalid
pointer.  (And from the rest of your message it looks like that's what
happened.)

This is the reason why pointers have offsets, that's probably the way
to solve your problem.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.