From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id UAA17052; Thu, 18 Sep 2003 20:18:38 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA04069 for ; Thu, 18 Sep 2003 20:18:36 +0200 (MET DST) Received: from old.davidb.org (adsl-64-175-171-246.dsl.sndg02.pacbell.net [64.175.171.246]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h8IIIY501346 for ; Thu, 18 Sep 2003 20:18:35 +0200 (MET DST) Received: from davidb by old.davidb.org with local (Exim 3.36 #1 (Debian)) id 1A03GJ-000295-00; Thu, 18 Sep 2003 11:12:15 -0700 Date: Thu, 18 Sep 2003 11:12:15 -0700 From: David Brown To: Michael Wohlwend Cc: caml-list@inria.fr Subject: Re: [Caml-list] c-interface question... Message-ID: <20030918181215.GA8189@davidb.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.4i X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 caml-list:01 c-interface:01 wohlwend:01 camlparam:01 camlparamx:01 camlparam:01 camlparamx:01 camllocal:01 allocates:01 garbage:01 garbage:01 0200,:01 sep:01 collector:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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