From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 35667BB83 for ; Mon, 14 Aug 2006 02:48:30 +0200 (CEST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k7E0mSU0013405 for ; Mon, 14 Aug 2006 02:48:29 +0200 Received: from localhost (suiren [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.13.7/8.13.7) with ESMTP id k7E0Km5g013513; Mon, 14 Aug 2006 09:20:48 +0900 (JST) Date: Mon, 14 Aug 2006 09:20:46 +0900 (JST) Message-Id: <20060814.092046.03363783.garrigue@math.nagoya-u.ac.jp> To: micha-1@fantasymail.de Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] question about how to bind c++ classes to ocaml From: Jacques Garrigue In-Reply-To: <20060813224715.0769efc9@localhost> References: <20060813224715.0769efc9@localhost> X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 44DFC85C.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; ocaml:01 ocaml:01 allways:01 caml-list:01 functions:01 functions:01 variables:02 variables:02 native:02 binding:02 binding:02 string:02 garrigue:03 garrigue:03 seems:03 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 From: micha > when binding an ocaml class to a c++ class, what's the preferred > way to access member variables of the c++ class? > One is just to implement the get and set function in ocaml to call > the native get/set functions of the c++ class. That way you allways have > some calls from ocaml to c only to get a value of a c++ object. > Another way would be to add similar member variables to the ocaml class > and everytime the c++ side changes a member it updates the ocaml side > too (through direct access). This way you have an additional binding > (the c++ object knows it's ocaml object), but you can access the member > variables in ocaml through normal ocaml methods. I suppose this very much depends on how you intend to use this binding, but trying to synchronize members between C++ and ocaml seems a lot of work. The only advantage is faster read access, so this should only be done if you have to read this member often, and the cost is significant. There is also the induced cost of calling back ocaml every time the member is updated. Calls from ocaml to C are very cheap. If your access function doesn't do any allocation (i.e. never calls the GC), you can even make it faster by marking it as "noalloc". Beware many functions do allocate, including copy_double or copy_string. Jacques Garrigue