Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Win32 API
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Harry Chomsky <harry@c...>
Subject: Re: [Caml-list] Win32 API
> When you
> call an OCaml alloc function, all your variables of type "value" may
> point to wrong places.

OK, I think I'm understanding this better now.  So if a C function does all
of its work using simple macros like Val_int then it's ok, but if it does
anything that might cause the OCaml runtime to allocate memory, then it has
to use the CAMLparam and CAMLreturn macros as described in the
documentation.  Is that right?

Now I understand also why the naming conventions differ so radically between
e.g. Val_int and copy_int32.  Clearly the former just manipulates bits while
the latter allocates memory.  I had thought this was an insignificant
distinction, so when I wrote functions like copy_int32 I named them
Val_handle etc.  I thought this made the code read more easily.  But I see
now why the distinction matters.

I will go through my existing code to make it use the CAML* macros where
necessary and rename the Val_* functions to copy_*.  I'll write to the list
again when I have posted these modifications.

(To the writers of the [mostly superb] documentation: The rules listed in
"Living in harmony with the garbage collector" are very clear, but most of
the sample C code in the other sections of the chapter don't follow the
rules.  Perhaps the documentation could explain not just how to follow the
rules but also *when* to follow them, and why they are ignored in those
samples.  Thanks!)

-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr