caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* memory handling with native code
@ 2006-08-24  8:59 Michael Wohlwend
  2006-08-24 15:46 ` [Caml-list] " skaller
  2006-08-24 16:47 ` Bardur Arantsson
  0 siblings, 2 replies; 3+ messages in thread
From: Michael Wohlwend @ 2006-08-24  8:59 UTC (permalink / raw)
  To: caml-list

I'm trying to make an interface to a c++ lib of a friend of me, it's getting better, but questions about the memory management came up:

Say there is a c++ class widget, which I want to mirror on the ocaml side. So I implemented a c++ widget-adapter, which inherits from widget and forwards events to the ocaml widget class. This works fine, but how to delete the widget adapter? In the case the ocaml class gets destroyed by the gc the adapter on the native side is still there.
Should I wrap the pointer in a custom object?

cheers,
 Michael

-- 


"Feel free" – 10 GB Mailbox, 100 FreeSMS/Monat ...
Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] memory handling with native code
  2006-08-24  8:59 memory handling with native code Michael Wohlwend
@ 2006-08-24 15:46 ` skaller
  2006-08-24 16:47 ` Bardur Arantsson
  1 sibling, 0 replies; 3+ messages in thread
From: skaller @ 2006-08-24 15:46 UTC (permalink / raw)
  To: Michael Wohlwend; +Cc: caml-list

On Thu, 2006-08-24 at 10:59 +0200, Michael Wohlwend wrote:

FYI: your email client is not correctly formatting email.
It allows paragraphs to consist of one long line. The email RFC
does not allow this. Please line break manually, around 60 characters.

My client  line-breaks your text on reading, but it does not do so in 
quotations ;(

> So I implemented a c++ widget-adapter, which inherits from widget 
> and forwards events to the ocaml widget class. 
> This works fine, but how to delete the widget adapter? 

You can use a finaliser. Look in the Gc module.
This ensures the object is not deleted whilst the Ocaml
object remains reachable. The finaliser is ordinary
Ocaml code, which can call a C routine to do the deletion.
You don't need a custom block for this, but you do need
to wrap the constructor/binder logic to ensure the
Ocaml finaliser is applied to the object.

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: memory handling with native code
  2006-08-24  8:59 memory handling with native code Michael Wohlwend
  2006-08-24 15:46 ` [Caml-list] " skaller
@ 2006-08-24 16:47 ` Bardur Arantsson
  1 sibling, 0 replies; 3+ messages in thread
From: Bardur Arantsson @ 2006-08-24 16:47 UTC (permalink / raw)
  To: caml-list

Michael Wohlwend wrote:
> I'm trying to make an interface to a c++ lib of a friend of me, it's getting better, but questions about 
 > the memory management came up:
> Should I wrap the pointer in a custom object?
[-- snip mumble about unbroken lines ;) --]

Since we're on this subject: I was wondering whether anyone on the list 
has investigated if it's possible to use the C++ boost::shared_ptr<> or 
tr1::shared_ptr<> for that matter and OCaml's custom blocks to 
interoperate so that one can avoid having to do manual custom 
block/pointer management on the C/C++ side of things?

I've always found the manual custom block/pointer management to be one 
of the more annoying aspects of OCaml's FFI.

Cheers,

-- 
Bardur Arantsson
<bardurREMOVE@THISscientician.net>

- I didn't have a blunt object with me, so I said "OK".
                                  David Letterman, 'The Late Show'


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-08-24 16:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-24  8:59 memory handling with native code Michael Wohlwend
2006-08-24 15:46 ` [Caml-list] " skaller
2006-08-24 16:47 ` Bardur Arantsson

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).