English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
wrapping external classes
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-12-11 (15:08)
From: Alain Frisch <alain@f...>
Subject: Re: [Caml-list] wrapping external classes
Mauricio Fernandez wrote:
> class foo s n =
> object(self)
>   val handle = create s n
> 
>   method compute = compute handle
> 
>   initializer
>     (* use a destroy method explicitly if you need to make sure the destructor
>      * is called --- Gc.finalise doesn't guarantee this (e.g. the program might
>      * terminate before the finalisation function is executed) *)
>     Gc.finalise destroy handle
> end

If the handle is really an OCaml integer, it is not possible to attach a 
finalizer to it. The finalizer could be attached to the object that 
wraps the handle; but the best solution is to use custom blocks and C 
finalizers in the C binding.

-- Alain