Browse thread
[Caml-list] Marshalling objects (was: French interactive fiction, anyone ?)
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2002-06-20 (05:09) |
From: | Jacques Garrigue <garrigue@k...> |
Subject: | Re: [Caml-list] Marshalling objects (was: French interactive fiction, anyone ?) |
From: Berke Durak <berke@altern.org> > Well, this is not exactly about marshalling code : I'm not asking > Ocaml to be able to transfer pieces of code between different > programs. Just being able to save an object and reload it in the same > executable later would suffice : since Caml can save closures under > the same constraints, the reason why objects can't be saved must be > something else. Actually I cannot remember any such reason. I actually tried, just commenting out the Object_tag case in byterun/extern.c, and it works! There's a single glitch: as it just handles objects as normal data, oid's are not updated. This means that equality on objects (which is oid based) will be incorrect. Can somebody comment about other possible problems? I join some test code at the end of this mail, to run after commenting out Object_tag. On the other hand, objects are not just closures, and it would be nice to be able to serialize their data in a code-independent way. Not so unreasonable: class names are unique. This would require a bit of runtime support, to be able to retrieve method tables. Jacques Garrigue (* objext.ml *) class c (n : int) = object (self) method private n = n method get_n = self#n method show = string_of_int self#n end let () = let o = if Sys.file_exists "objext.dat" then let ic = open_in "objext.dat" in let o : c = input_value ic in close_in ic; Printf.printf "old value: %s\n" o#show; let o' = new c (o#get_n + 1) in Printf.printf "new value: %s\n" o'#show; Printf.printf "old %s new\n" (if o = o' then "=" else "<>"); o' else begin print_endline "created objext.dat"; new c 0 end in let oc = open_out "objext.dat" in Marshal.to_channel oc o [Marshal.Closures]; close_out oc ------------------- 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