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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: David Brown <caml-list@d...>
Subject: Re: [Caml-list] c-interface question...
On Thu, Sep 18, 2003 at 10:31:20AM +0200, Michael Wohlwend wrote:

> external md5_new : unit -> md5_context = "md5_new"
> 
> should it be:
> 
> CAMLparam1(unit);

> as it receives a unit-paramter?

It won't hurt anything to do this, other than performance.  The only
arguments that need to be declared in a CAMLparamx declaration are those
that can be moved or collected by the garbage collector.  Specifically,
integer values do not need to be declared.

There is also no need to CAMLparam an argument that you do not use, even
if it is a heap value.

An added "optimization" is that if an argument is only used before the
first allocation you call, it also doesn't need to be declared.

It helps to think about what is happening here.  Things that allocate
memory may trigger a garbage collection.  If you have arguments or
variables that might be affected by the garbage collector, you need to
tell the gc about them.  That is what CAMLparamx and CAMLlocal do.

A function that only allocates one thing, and doesn't reference its
variables after the allocation doesn't need to use any of these macros.

Dave Brown

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners