caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: caml-list@inria.fr
Subject: Re: [Caml-list] [CAML liist] :: how to reduce depply recursive ocaml program's memory usage
Date: Tue, 9 Apr 2013 13:04:38 +0200	[thread overview]
Message-ID: <20130409110438.GA22701@frosties> (raw)
In-Reply-To: <388323f0.3cf7.13dde5b5ae6.Coremail.syshen@nudt.edu.cn>

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

      reply	other threads:[~2013-04-09 11:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-06  7:59 沈胜宇
2013-04-09 11:04 ` Goswin von Brederlow [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130409110438.GA22701@frosties \
    --to=goswin-v-b@web.de \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).