Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
How to wrap around C++?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2010-02-09 (06:53)
From: Basile STARYNKEVITCH <basile@s...>
Subject: Re: [Caml-list] Re: How to wrap around C++?
Guillaume Yziquel wrote:
> Essentially, the garbage collector will run potentially each time you 
> allocate an OCaml value. caml_copy_string? the GC may run.

The garbage collector may also run when calling (from C or C++ code) a callback, that is a function like caml_callback 
... (see section 18.7 of the manual), since this apply an Ocaml closure which of course will allocate Ocaml values.

In practical terms, you should consider that the Ocaml GC can be invoked by any C function from the Ocaml runtime (as 
seen by your C or C++ code) and that it moves pointers at every invocation.

So you better be safe and play carefully Ocaml rules.

Unless you really understand all the details of Ocaml runtime, I strongly recommend against playing tricks with Ocaml, 
for instance trying to avoid CAMLlocalX or CAMLparamX or CAMLreturn macros.

email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***