caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <xavier.leroy@inria.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] What's the best practice for bindings for c++ templates?
Date: Wed, 29 Jul 2015 11:27:44 +0200	[thread overview]
Message-ID: <55B89C90.1040600@inria.fr> (raw)
In-Reply-To: <20150728184042.GA28321@frosties>

On 28/07/2015 20:40, Goswin von Brederlow wrote:
> Hi,
> 
> I'm halfway done writing a c++ library for a network protocol and
> considering writing some bindings for ocaml. The library uses
> templates to make objects customizable and am wondering what the best
> practice is there. [...]
> 
> 1) For the stub code I need to instantiate the template with 'a, which
> obviously doesn't work since the C++ stub has no idea about what type
> ocaml will use in the future.
> 
> So do I instantiate it with void *? uintptr_t? value?
> 
> 2) I'm storing ocaml values in C++ structures and getting them back.
> How do I make that play nice with the GC?

My C++ is rusty, but perhaps you could use the "smart pointer" pattern
to equip OCaml's "value" type with appropriate constructors,
destructors and assignment operations ("appropriate" meaning that they
register and unregister the address of the value with the GC as
needed).  Then, you would instantiate your template with this
"smart value" type.  Just an idea.

- Xavier Leroy

  reply	other threads:[~2015-07-29  9:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-28 18:40 Goswin von Brederlow
2015-07-29  9:27 ` Xavier Leroy [this message]
2015-07-29 12:36 ` AW: " Bauer, Christoph
2015-07-30 18:00   ` Goswin von Brederlow

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=55B89C90.1040600@inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=caml-list@inria.fr \
    /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).