From: Dominik Brugger <dominikbrugger@gmx.de>
To: caml-list@yquem.inria.fr
Cc: Dominik Brugger <dominikbrugger@fastmail.fm>
Subject: Re: Ocaml C interface - Usage of custom blocks
Date: Thu, 22 Sep 2005 11:20:26 +0000 [thread overview]
Message-ID: <87y85pgxhh.fsf@gmx.de> (raw)
Is there a "best practice" for returning C data to OCaml
which was allocated by malloc?
One way to do this is given by the curses library example
in the OCaml reference manual in section 18.6:
value curses_initscr(value unit)
{
CAMLparam1 (unit);
CAMLreturn ((value) initscr()); /* OK to coerce directly from WINDOW * to
value since that's a block created by malloc() */
}
But section 18.2.3 of the manual points out, that it is potentially
dangerous to free C data, as it might be reclaimed by the OCaml GC.
So what happens if the data is never explicitly freed? Does the OCaml heap
space grow until there is no more memory available to the C part of the
OCaml program?
In my opinion the only way to avoid these problems is the usage of
OCaml custom blocks.
Dominik
next reply other threads:[~2005-09-22 10:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-09-22 11:20 Dominik Brugger [this message]
2005-09-22 18:33 ` [Caml-list] " Lukasz Stafiniak
2005-09-23 7:54 ` 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=87y85pgxhh.fsf@gmx.de \
--to=dominikbrugger@gmx.de \
--cc=caml-list@yquem.inria.fr \
--cc=dominikbrugger@fastmail.fm \
/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