Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Why always out_of _memory
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Markus Mottl <markus@o...>
Subject: Re: [Caml-list] Why always out_of _memory
On Fri, 20 Dec 2002, onlyclimb wrote:
>  why i always encounter out_of_memory error?
> 1  let mem_leaves tr n = let lf = Res.Array.to_array tr.leaves in
> 2                       try
> 3                        for i = 0 to Array.length lf -1 do
> 4                            if n = lf.(i) then raise Exit
> 5                          done; false
> 6                        with Exit -> true

I guess that your leaves are part of cycles. Thus, the comparison function
may get into troubles...

E.g.:

  type t = { a : t; b : unit }

  let rec x = { a = x; b = () }
  let rec y = { a = y; b = () }

  let _ = print_endline (string_of_bool (x = y))

The above code will lead to "Out of memory".

Note that putting "b : unit" first in the type definition just leads
to non-termination, because the comparison function can finish on the
first field and descend tail-recursively into the second part, thus
looping forever.

Further note: comparing "x = x" will finish succesfully, because pointer
equality is always checked for structures.

Regards,
Markus Mottl

-- 
Markus Mottl                                             markus@oefai.at
Austrian Research Institute
for Artificial Intelligence                  http://www.oefai.at/~markus
-------------------
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