caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Richard Jones <rich@annexia.org>
To: Jonathan Roewen <jonathan.roewen@gmail.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] GC, Anonymous Functions, and C
Date: Fri, 17 Dec 2004 22:56:02 +0000	[thread overview]
Message-ID: <20041217225602.GA8550@annexia.org> (raw)
In-Reply-To: <ad8cfe7e0412171355b901128@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1131 bytes --]

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.

Rich.

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

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

  reply	other threads:[~2004-12-17 22:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-17 21:55 Jonathan Roewen
2004-12-17 22:56 ` Richard Jones [this message]
2004-12-17 23:05 ` David Brown
2004-12-17 23:09 ` Damien Doligez

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=20041217225602.GA8550@annexia.org \
    --to=rich@annexia.org \
    --cc=caml-list@yquem.inria.fr \
    --cc=jonathan.roewen@gmail.com \
    /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).