|Anonymous | Login | Signup for a new account||2015-11-30 12:43 CET|
|Main | My View | View Issues | Change Log | Roadmap|
|View Issue Details|
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0000381||OCaml||OCaml general||public||2001-06-08 15:20||2001-06-12 16:21|
|Status||closed||Resolution||no change required|
|Target Version||Fixed in Version|
|Summary||0000381: Marshal an object?|
|Description||Is it ever possible to marshal an object? At run-time you have the dynamic|
type of the object so you should be able to resolve any questions about
what the object actually is. But even simple programs (see below) that
marshal objects choke with Invalid_Argument("Object value") (or somesuch).
I've tried ocaml 2.04 and 3.01. Is there any hope or is this just not
(* this code fails at run-time *)
class myclass =
method name = "hello";
val info : int = 32;
let m = new myclass ;;
let oc = open_out_bin "output" ;;
let _ = Marshal.to_channel oc m [Marshal.Closures] ;; (* we die here *)
let _ = Printf.printf "Done!\n" ;;
|Tags||No tags attached.|
> Is it ever possible to marshal an object?
> At run-time you have the dynamic
> type of the object so you should be able to resolve any questions about
> what the object actually is.
Like functions, objects contain both data and code (via the vtable
pointers). Marshalling data is easy, but marshalling code isn't.
Actually sending the code along the wire requires position-independent
code, which OCaml doesn't generate currently, and can result in quite
large amounts of data. Marshalling just a reference to the code (or
to the class), like Java does, is quite tricky, at least if you want
to make sure that the code at the other end will match.
The Marshall.Closures flag sort of solves the issue for pure functions
(but requires that the reader program be exactly identical to the
writer program, which is a strong restriction in practice), but there
are additional issues for objects related to the structure of vtables
that render this approach ineffective for objects (currently).
JoCaml (a distributed extension of OCaml based on the join-calculus)
does something along these lines, but the solution is tricky and quite
specific to JoCaml (it needs a bidirectional connection between the
sender and the receiver, as far as I can remember, so it doesn't
extend to marshalling to files). We're still scratching our heads
trying to design a more general solution, but don't hold your breath.
In the meantime, you could work around the problem by marshalling a
pure data structure extracted from the objects, and reconstructing the
objects from the data structure on the reader side.
- Xavier Leroy
|Not supported currently.|
|2005-11-18 10:13||administrator||New Issue|
|Copyright © 2000 - 2011 MantisBT Group|