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
[Caml-list] GC, Anonymous Functions, and C
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-12-17 (22:56)
From: Richard Jones <rich@a...>
Subject: Re: [Caml-list] GC, Anonymous Functions, and C
On Sat, Dec 18, 2004 at 10:55:23AM +1300, Jonathan Roewen wrote:
> Hi,
> When passing an anonymous ocaml function to a C function, is it safe
> to store that value in an array, and then call it later at an abitrary
> time, or will the GC reclaim it? And if so, what should be done to
> stop the GC from doing so?
> Basically, we're trying to do interrupt handling from OCaml, and need
> to store the anonymous functions somewhere for the IDT to jump into,
> to provide a little context for the problem.

The GC might reclaim the value (function, or whatever) unless you
register it as a global root.  To do this you need to call
caml_register_global_root on each value which you put in the array.
Furthermore you ought to call caml_remove_global_root when you remove
the value from the array and no longer need it.


Richard Jones.  http://www.annexia.org/  http://www.j-london.com/
>>>   http://www.team-notepad.com/ - collaboration tools for teams   <<<
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
http://youunlimited.co.uk/ - Personal improvement courses