From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id B7D7E7EE51 for ; Tue, 9 Apr 2013 13:04:40 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of goswin-v-b@web.de) identity=pra; client-ip=212.227.15.3; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of goswin-v-b@web.de) identity=mailfrom; client-ip=212.227.15.3; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mout.web.de) identity=helo; client-ip=212.227.15.3; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="postmaster@mout.web.de"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtUCAIr0Y1HU4w8Dm2dsb2JhbABRv1+FH4ESFg4BAQEBAQYLCwkUKIIfAQEFOk8LGAklDwUoiDUBFq4VhggfihWPKRaCSmEDlnOFcYxygTg X-IPAS-Result: AtUCAIr0Y1HU4w8Dm2dsb2JhbABRv1+FH4ESFg4BAQEBAQYLCwkUKIIfAQEFOk8LGAklDwUoiDUBFq4VhggfihWPKRaCSmEDlnOFcYxygTg X-IronPort-AV: E=Sophos;i="4.87,438,1363129200"; d="scan'208";a="12458081" Received: from mout.web.de ([212.227.15.3]) by mail2-smtp-roc.national.inria.fr with ESMTP; 09 Apr 2013 13:04:40 +0200 Received: from frosties.localnet ([95.208.119.3]) by smtp.web.de (mrweb003) with ESMTPSA (Nemesis) id 0LmLac-1Uy25d0UOw-00ZFVR for ; Tue, 09 Apr 2013 13:04:39 +0200 Received: from mrvn by frosties.localnet with local (Exim 4.80) (envelope-from ) id 1UPWLu-0005jh-I5 for caml-list@inria.fr; Tue, 09 Apr 2013 13:04:38 +0200 Date: Tue, 9 Apr 2013 13:04:38 +0200 From: Goswin von Brederlow To: caml-list@inria.fr Message-ID: <20130409110438.GA22701@frosties> References: <388323f0.3cf7.13dde5b5ae6.Coremail.syshen@nudt.edu.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <388323f0.3cf7.13dde5b5ae6.Coremail.syshen@nudt.edu.cn> User-Agent: Mutt/1.5.21 (2010-09-15) X-Provags-ID: V02:K0:CzgYOZGZ/ElQUeC/QVSy04yKtWU2s4kBuvx03b7HpQ6 jgEVOmPus2jWJMSAiXTXsVbKn7oXWXpGpy/YynSmGYUMmaMghX wRL+E9wS5q7pMQt/7/GsVhycZIRKVymcRHLFLOdBTJGAcebteG lkoIIU1lAXYjI+Q/UzDSwBFLPuVcUzvFUD1WmdVEVzn03SHmWk 9x6aBgYGV8yLjrwZ8TSdQ== Subject: Re: [Caml-list] [CAML liist] :: how to reduce depply recursive ocaml program's memory usage On Sat, Apr 06, 2013 at 03:59:21PM +0800, ?????? wrote: > Dear all: > > > I have a deeply recursive ocaml program in the following way: > > > method A begin > calling B > end > > > method B begin > calling A > end > > > > > in A and B, there are lots of local let bindings liek: > > > let c=... in > let d=f(c) > > > so by changing it to > > > let d= begin > let c = ... in > f(c) > end > > > can I reduce the memory usage? I don't know. Can you? Why don't you just test this? I'm not sure how much ocaml analyses the lifetime of a variable so explicitly limiting it might help. But what helps a lot more is making the recursive calls tail recursive. That way only the variables of the current function remain alive and you will have a constant memory footprint no matter how deep the recursion. MfG Goswin