From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 74327BC57 for ; Wed, 8 Sep 2010 00:53:42 +0200 (CEST) X-IronPort-AV: E=Sophos;i="4.56,330,1280700000"; d="scan'208";a="69030606" Received: from arouen-752-1-17-15.w90-51.abo.wanadoo.fr (HELO macadam.home) ([90.51.128.15]) by mail4-relais-sop.national.inria.fr with ESMTP/TLS/AES128-SHA; 08 Sep 2010 00:53:40 +0200 Subject: Re: [Caml-list] C binding and GC interaction: storing values outside the heap Mime-Version: 1.0 (Apple Message framework v1081) Content-Type: text/plain; charset=us-ascii From: Damien Doligez In-Reply-To: Date: Wed, 8 Sep 2010 00:53:39 +0200 Cc: OCaml mailing list , OCaml-Lua devel ML Content-Transfer-Encoding: quoted-printable Message-Id: <8DF23B0B-D2D5-45CE-99B1-37EA0C8BD4C6@inria.fr> References: To: Paolo Donadeo X-Mailer: Apple Mail (2.1081) X-Spam: no; 0.00; damien:01 damien:01 ocaml:01 ocaml:01 struct:01 hash:01 hashing:01 hash:01 doligez:01 doligez:01 wrote:01 heap:01 caml-list:01 data:02 data:02 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