* [Caml-list] [CAML liist] :: how to reduce depply recursive ocaml program's memory usage
@ 2013-04-06 7:59 沈胜宇
2013-04-09 11:04 ` Goswin von Brederlow
0 siblings, 1 reply; 2+ messages in thread
From: 沈胜宇 @ 2013-04-06 7:59 UTC (permalink / raw)
To: caml-list
[-- Attachment #1: Type: text/plain, Size: 325 bytes --]
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?
Shen
[-- Attachment #2: Type: text/html, Size: 640 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] [CAML liist] :: how to reduce depply recursive ocaml program's memory usage
2013-04-06 7:59 [Caml-list] [CAML liist] :: how to reduce depply recursive ocaml program's memory usage 沈胜宇
@ 2013-04-09 11:04 ` Goswin von Brederlow
0 siblings, 0 replies; 2+ messages in thread
From: Goswin von Brederlow @ 2013-04-09 11:04 UTC (permalink / raw)
To: caml-list
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-04-09 11:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-06 7:59 [Caml-list] [CAML liist] :: how to reduce depply recursive ocaml program's memory usage 沈胜宇
2013-04-09 11:04 ` Goswin von Brederlow
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox