Hello Mark, > >> 'make-c-struct' copies the C pointers from those foreign pointer objects, > >> but > >> not not keep a reference to the objects themselves.
> > To me, this sounds very counter intuitive, actually, it sounds like a bug, > > make-c-struct should be holding a reference to the pointers it receives: i > > seems > > to me that only when the c-struct itself becomes unreachable, that these > > pointers could be freed? > In my previous email I described some practical difficulties with > implementing this suggestion, but I should rather emphasize a more > important point: > 'make-c-struct' is ultimately meant for passing data to C, and in > general you should assume that Boehm GC will _not_ see references from C > data structures to your GC-allocated objects. > In fact, Boehm GC does _not_ scan objects allocated using C 'malloc', > nor C++ 'new', nor 'make-c-struct'. So, for purposes of garbage > collection, you should normally assume that passing pointers to C land > is equivalent to passing them to a block hole. > In general, when passing GC-allocated objects to C code, unless the C > code in question was written with Boehm GC in mind, you must always > think about how long the object must be kept alive, and arrange to keep > a reference to it for at least that long, and preferably no longer than > necessary or else you'll have space leaks. > I'm open to suggestions of how to make this better, although I'm also > fairly confident that interfacing between GC-managed and non-GC-managed > code is a thorny problem with no silver bullets. Answering the second of your 2 emails, but I did read the first as well ... I agree with you, I think I somehow was only looking at one (of the many) way users may use make-c-struct/parse-c-struct, and indeed I now see that my request would even lead to mem problem, since most of the time, C may change these pointers or any other struct field(s) content ... Thanks again for your time and very good explanations. Cheers, David
pgpCNSJCWcXIi.pgp
Description: OpenPGP digital signature