Thanks Sylvain for the quick response!

-Just checked out the Gc module, pretty slick...I'll find this useful
in the future.
-I actually just figured out the problem through experimentation. I
did not see this issue mentioned in any of the manuals I read on OCaml
(including the manual). The problem was not a lack of CAMLparam*
declarations, but rather an overuse of them. I have a habit of writing
in a declarative style, so I'll break down the C implementation of the
call I'm trying to wrap into multiple functions which take values of
type "value":

e.g.
int intermediate_func(value mlVal)
{
    CAMLparam1(mlVal); /*This is incorrect! */

}

CAMLprim value func_to_wrap(value mlVal)
{
    CAMLparam1(mlVal);
    CAMLreturn(toReturn);
}








On Jan 17, 6:01 am, Sylvain Le Gall <[email protected]> wrote:
> Hello,
>
> On 17-01-2011, mas <[email protected]> wrote:
>
>
>
>
>
>
>
>
>
> > Hello all,
> > I've been struggling with a problem with OCaml's C interface and can't
> > seem to deduce the problem. Here's what's going on in a nutshell:
>
> > - I used OCaml's C interface to develop a series of OCaml wrappers for
> > C functions.
> > - The functions operate correctly for the most part....however when I
> > call the functions repeatedly (anywhere between a dozen to a few
> > hundred invocations), the function does not return and locks up.
> > - I have been able to track down the problem to points where I call
> > caml memory allocation calls (e.g. caml_copy_double) in the C code.
> > Turns out that on random occasions this function does not return and
> > ends up utilizing 100% of the CPU!
>
> > My gut feeling is that I'm exceeding the memory size the OCaml runtime
> > allocates for its internal C stack/heap and the call fails. Rather
> > than return something like a NULL, my guess is that the allocator is
> > waiting for space to free up. However as there is no error message or
> > indication of what is failing, I'm not sure what to do. Any ideas for
> > what this could be and how I can find more info? Is there any way I
> > can print out info about the VM state?
>
> You can get various VM info through the Gc module.
>
> The best you can do is to provide us with a minimal example of what is
> not working. You can even try to call Gc.compact/full_major/major/minor
> that should help to speed up memory problems...
>
> The most common problem with OCaml/C stub is the lack of CAMLparamX,
> CAMLlocal or CAMLreturn which leads to inconsistent memory.
>
> Cheers,
> Sylvain Le Gall
> --
> My company:http://www.ocamlcore.com
> Linkedin:  http://fr.linkedin.com/in/sylvainlegall
> Start an OCaml project here:http://forge.ocamlcore.org
> OCaml blogs:                http://planet.ocamlcore.org

-- 
You received this message because you are subscribed to the Google Groups 
"ocaml-developer" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/ocaml-developer?hl=en
For other OCaml forums, see http://caml.inria.fr/resources/forums.en.html

Reply via email to