caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <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
Date: Mon, 14 Aug 2006 09:20:46 +0900 (JST)	[thread overview]
Message-ID: <20060814.092046.03363783.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <20060813224715.0769efc9@localhost>

From: micha <micha-1@fantasymail.de>

> 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


  reply	other threads:[~2006-08-14  0:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-13 20:47 micha
2006-08-14  0:20 ` Jacques Garrigue [this message]
2006-08-14  7:04   ` [Caml-list] " Jonathan Roewen
2006-08-14  7:17   ` Michael Wohlwend
2006-08-14  8:45     ` Jacques Garrigue

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060814.092046.03363783.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@yquem.inria.fr \
    --cc=micha-1@fantasymail.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).