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: onlyclimb <onlyclimb@1...>
Subject: [Caml-list] Why always out_of _memory
  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