* [Caml-list] Why always out_of _memory
@ 2002-12-20 20:40 onlyclimb
2002-12-20 13:30 ` Markus Mottl
0 siblings, 1 reply; 2+ messages in thread
From: onlyclimb @ 2002-12-20 20:40 UTC (permalink / raw)
To: caml-list
why i always encounter out_of_memory error?
it is a function of my tree with type
type ('a,'b) t ={ mutable name : string ;
mutable nodes : ('a,'b) Node.t Res.Array.t ;
mutable root : ('a,'b) Node.t;
mutable leaves : ('a,'b) Node.t Res.Array.t
}
val mem_leaves : ('a,'b) t -> ('a,'b) Node.t -> bool
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
for fear that if Res.Array.mem has problem , i change the it into a
standard array version
using Res.Array.to_array . However , problem still exsits
here is the snapshot of ocamldebug just before Out_of_memory error
Time : 1070 - pc : 94780 - module Tree
145 <|b|>if n = lf.(i) then raise Exit
(ocd) p n
n : ('a, 'b) Node.t = <abstr>
(ocd) p i
i : int = 2
(ocd) p lf
lf : ('a, 'b) Node.t array =
[|<abstr>; <abstr>; <abstr>; <abstr>; <abstr>; <abstr>|]
(ocd) s
Time : 1071
Program end.
Uncaught exception: Out_of_memory
Here is the testing code
let _ =
let tr = maketree in (*make a tree with 6 leaves*)
print_newline();
let lf = Tree.get_leaves tr in
Res.Array.iter print lf; (* val print : ('a,'b) Node.t -> unit*)
print_newline();
let alf = Res.Array.get lf 3 in
print_string "Node at index 3 in lf is : ";
print alf;
let b =Tree.mem_leaves tr alf in (* here throw the out_of_memeroy*)
print_string (string_of_bool b)
out put is:
n5(4) -> n6(4) -> n7(3) -> n9(3) -> n10(3) -> n8(2) ->
Node at index 3 in lf is : n9(3) -> Fatal error: exception Out_of_memory
here n5 is the node name , (4) is node 's level num
it has 6 leaves in the tree
I think it is a simple situation. but i dont know where is the problem ?
Can anybody help me ?
Thanks
climb
-------------------
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] Why always out_of _memory
2002-12-20 20:40 [Caml-list] Why always out_of _memory onlyclimb
@ 2002-12-20 13:30 ` Markus Mottl
0 siblings, 0 replies; 2+ messages in thread
From: Markus Mottl @ 2002-12-20 13:30 UTC (permalink / raw)
To: onlyclimb; +Cc: caml-list
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-12-20 13:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-20 20:40 [Caml-list] Why always out_of _memory onlyclimb
2002-12-20 13:30 ` Markus Mottl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox