Browse thread
Re: Ocaml C interface - Usage of custom blocks
- Dominik Brugger
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Dominik Brugger <dominikbrugger@g...> |
| Subject: | Re: Ocaml C interface - Usage of custom blocks |
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