Version française
Home     About     Download     Resources     Contact us    
Browse thread
C binding and GC interaction: storing values outside the heap
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Damien Doligez <damien.doligez@i...>
Subject: Re: [Caml-list] C binding and GC interaction: storing values outside the heap

On 2010-09-07, at 22:58, Paolo Donadeo wrote:

> The problem is that, for several good reasons, I need a copy, or a reference, to the OCaml value representing the lua_State (v_L in the code above) inside the Lua state (I mean the C data structure).

That creates a cross-heap reference loop and it's very bad news for the GC.

> As a temporary workaround I removed the "value state_value" field from the ocaml_data struct, replacing it with a reference counter:

Maybe you could try something similar, with a weak hash table to recover the
OCaml value corresponding to a given lua_State, thus eliminating the need for
a reference counter.  Use the address of the lua_State for hashing and for
comparison.

Drawback: the weak hash table has to be global.

-- Damien