From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: ** X-Spam-Status: No, score=2.1 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE, HTML_MESSAGE,INFO_TLD,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 70556BC68 for ; Thu, 26 Oct 2006 16:54:45 +0200 (CEST) Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.231]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id k9QEsiHH008485 for ; Thu, 26 Oct 2006 16:54:44 +0200 Received: by wx-out-0506.google.com with SMTP id s7so419021wxc for ; Thu, 26 Oct 2006 07:54:44 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=TcN3egltdMdToxEn3IBE1IgmZHVA0P/+NVVNoi6UhKR0OeoZLC9zmaiueHjsfYQF18RNfrdnabhQw3oyq62iPnQcf6pjUultj6Q1wzS6rSLsPH8+xVqCvG6zJyVU9X+cILQOOFjl0vbt1OPPiS6j5/ddfKhO9wVYzOwoePgRknk= Received: by 10.70.111.2 with SMTP id j2mr3504241wxc; Thu, 26 Oct 2006 07:54:43 -0700 (PDT) Received: by 10.70.16.10 with HTTP; Thu, 26 Oct 2006 07:54:43 -0700 (PDT) Message-ID: Date: Thu, 26 Oct 2006 10:54:43 -0400 From: "Markus Mottl" To: "Hendrik Tews" Subject: Re: [Caml-list] caml_oldify_local_roots takes 50% of the total runtime Cc: caml-list@inria.fr In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_33692_8794520.1161874483517" References: <17727.34685.561877.977822@tandem.cs.ru.nl> X-j-chkmail-Score: MSGID : 4540CC34.000 on discorde : j-chkmail score : X : 0/20 1 X-Miltered: at discorde with ID 4540CC34.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; markus:01 mottl:01 markus:01 mottl:01 oldify:01 runtime:01 hendrik:01 tews:01 tews:01 pointers:01 ocaml:01 ocaml:01 pointers:01 ocaml-values:01 ocaml-value:01 ------=_Part_33692_8794520.1161874483517 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 10/26/06, Hendrik Tews wrote: > > I don't quite understand: I only have pointers from C++ to ocaml. > Once constructed the ocaml objects are completely independent > from the C++ ones. > Ok, I thought they were entangled, i.e. there were pointers in both directions. But you will still need to avoid storing OCaml-values in C++-values. If you want to prevent them from being reclaimed as long as the C++-objects still refer to them, you'll have to store them in e.g. an OCaml-hashtable using e.g. integer keys as handles. Then you can store the key in the C++-object as an ordinary C++-value (i.e. no registering with the GC). If you need the OCaml-value on the C++-side, you just convert the handle to an OCaml-value, and execute a callback to look up the value associated with the handle in the hashtable. Btw., if you use an OCaml-int as handle you can store the "value" directly, because ints need not be registered with the GC anyway. Regards, Markus -- Markus Mottl http://www.ocaml.info markus.mottl@gmail.com ------=_Part_33692_8794520.1161874483517 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 10/26/06, Hendrik Tews <H.Tews@cs.ru.nl> wrote:
I don't quite understand: I only have pointers from C++ to ocaml.
Once constructed the ocaml objects are completely independent
from the C++ ones.

Ok, I thought they were entangled, i.e. there were pointers in both directions.  But you will still need to avoid storing OCaml-values in C++-values.

If you want to prevent them from being reclaimed as long as the C++-objects still refer to them, you'll have to store them in e.g. an OCaml-hashtable using e.g. integer keys as handles.  Then you can store the key in the C++-object as an ordinary C++-value ( i.e. no registering with the GC).  If you need the OCaml-value on the C++-side, you just convert the handle to an OCaml-value, and execute a callback to look up the value associated with the handle in the hashtable.  Btw., if you use an OCaml-int as handle you can store the "value" directly, because ints need not be registered with the GC anyway.

Regards,
Markus

--
Markus Mottl        http://www.ocaml.info        markus.mottl@gmail.com ------=_Part_33692_8794520.1161874483517--