caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: Ocaml C interface - Usage of custom blocks
@ 2005-09-22 11:20 Dominik Brugger
  2005-09-22 18:33 ` [Caml-list] " Lukasz Stafiniak
  0 siblings, 1 reply; 3+ messages in thread
From: Dominik Brugger @ 2005-09-22 11:20 UTC (permalink / raw)
  To: caml-list; +Cc: Dominik Brugger

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


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

end of thread, other threads:[~2005-09-23  7:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-22 11:20 Ocaml C interface - Usage of custom blocks Dominik Brugger
2005-09-22 18:33 ` [Caml-list] " Lukasz Stafiniak
2005-09-23  7:54   ` Damien Doligez

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