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
[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: 2003-09-18 (18:18)
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 Archives:
Bug reports: FAQ:
Beginner's list: