<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2002/12/78c90ba43648c2c49838d49e891910bc"
  from="Markus Mottl &lt;markus@o...&gt;"
  author="Markus Mottl"
  date="2002-12-20T13:30:34"
  subject="Re: [Caml-list] Why always out_of _memory"
  prev="2002/12/756c3fc027fc8ba373e7214c3dba2937"
  next="2002/12/15844ae4e1090111037f41a6baa2820a"
  prev-in-thread="2002/12/c1ae28de1841637e1625891d4f57a4a2"
  prev-thread="2002/12/d2c2fc4de35ce4234f61c8083211e1fb"
  next-thread="2002/12/756c3fc027fc8ba373e7214c3dba2937"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Why always out_of _memory">
<msg 
  url="2002/12/c1ae28de1841637e1625891d4f57a4a2"
  from="onlyclimb &lt;onlyclimb@1...&gt;"
  author="onlyclimb"
  date="2002-12-20T12:41:39"
  subject="[Caml-list] Why always out_of _memory">
<msg 
  url="2002/12/78c90ba43648c2c49838d49e891910bc"
  from="Markus Mottl &lt;markus@o...&gt;"
  author="Markus Mottl"
  date="2002-12-20T13:30:34"
  subject="Re: [Caml-list] Why always out_of _memory">
</msg>
</msg>
</thread>

<contents>
On Fri, 20 Dec 2002, onlyclimb wrote:
&gt;  why i always encounter out_of_memory error?
&gt; 1  let mem_leaves tr n = let lf = Res.Array.to_array tr.leaves in
&gt; 2                       try
&gt; 3                        for i = 0 to Array.length lf -1 do
&gt; 4                            if n = lf.(i) then raise Exit
&gt; 5                          done; false
&gt; 6                        with Exit -&gt; 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

</contents>

</message>

