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 KAA08122; Fri, 11 Jan 2002 10:25:30 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA08302 for caml-list@pauillac.inria.fr; Fri, 11 Jan 2002 10:25:29 +0100 (MET) 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 OAA26142 for ; Wed, 9 Jan 2002 14:28:09 +0100 (MET) Received: from julie.univ-savoie.fr (univax.univ-savoie.fr [193.48.120.32]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g09DS8P05933 for ; Wed, 9 Jan 2002 14:28:08 +0100 (MET) Received: from post.bourget.univ-savoie.fr (post.bourget.univ-savoie.fr [193.48.120.73]) by julie.univ-savoie.fr (8.9.3/jtpda-5.3.3) with ESMTP id OAA77309 for ; Wed, 9 Jan 2002 14:28:07 +0100 (CET) Received: from univ-savoie.fr (www.lama.univ-savoie.fr [193.48.123.134]) by post.bourget.univ-savoie.fr (8.12.0.Beta7/jtpda-5.3.3) with ESMTP id g09DS3O6010576 for ; Wed, 9 Jan 2002 14:28:03 +0100 Message-ID: <3C3C4567.511AA372@univ-savoie.fr> Date: Wed, 09 Jan 2002 14:28:07 +0100 From: Christophe Raffalli X-Mailer: Mozilla 4.77 [fr] (X11; U; Linux 2.2.16-9mdksmp i686) X-Accept-Language: en MIME-Version: 1.0 CC: caml-list@inria.fr Subject: [Caml-list] teil recursive function and GC References: <20020108110836.A9147@darling.home.br> Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello, It seems that the two follwing functions are not equivalent: the tail recursive version keeps pointers on all the intermediate sets and use a huge amount of memory (with around 200000 triangles) while the imperative version works well. I think the compiler should generate code that do not keep useless pointer accessible by the GC for tail recursive function calls (and also for other function call) ? (I use ocaml-3.03 with the native code compiler) Imperative version (it is only a piece of my code): let vertices_number = let adone = ref Vertex_set.empty in let count_vertices (p1,p2,p3) = adone := Vertex_set.add p1 (Vertex_set.add p2 (Vertex_set.add p3 !adone)) in List.iter count_vertices triangles; Vertex_set.cardinal !adone in let edges_number = let adone = ref Edge_set.empty in let count_edges (p1,p2,p3) = adone := Edge_set.add (p1,p2) (Edge_set.add (p2,p3) (Edge_set.add (p1,p3) !adone)) in List.iter count_edges triangles; Edge_set.cardinal !adone in Tail recursive version: let rec count_vertices adone ts = match ts with [] -> Vertex_set.cardinal adone | (p1,p2,p3)::ts -> count_vertices (Vertex_set.add p1 (Vertex_set.add p2 (Vertex_set.add p3 adone))) ts in let vertices_number = count_vertices Vertex_set.empty triangles in let rec count_edges adone ts = match ts with [] -> Edge_set.cardinal adone | (p1,p2,p3)::ts -> count_edges (Edge_set.add (p1,p2) (Edge_set.add (p2,p3) (Edge_set.add (p1,p3) adone ))) ts in let edges_number = count_edges Edge_set.empty triangles in -- Christophe Raffalli Université de Savoie Batiment Le Chablais, bureau 21 73376 Le Bourget-du-Lac Cedex tél: (33) 4 79 75 81 03 fax: (33) 4 79 75 87 42 mail: Christophe.Raffalli@univ-savoie.fr www: http://www.lama.univ-savoie.fr/~RAFFALLI ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr