* marshalling objects
@ 2005-11-11 4:54 Pietro Abate
2005-11-11 5:21 ` [Caml-list] " Jacques Garrigue
0 siblings, 1 reply; 6+ messages in thread
From: Pietro Abate @ 2005-11-11 4:54 UTC (permalink / raw)
To: ocaml ml
Hi all,
It's not clear to me if it is possible or not to marshall objects ? From
my tests it is not the case (output_value: abstract value (outside
heap).). Am I missing something ? What is common practice to send
objects across the wire ?
thanks,
p
--------- ex.ml
class node = object val d = 1 end ;;
let l =
try
let a = (new node) in
let s = (Marshal.to_string a [])
in print_endline "Success"; (Marshal.from_string s 0 : node)
with Invalid_argument s -> print_endline ("Failed "^s) ; (new node)
;;
let l =
try
let a = (new node) in
let s = (Marshal.to_string a [Marshal.Closures])
in print_endline "Success"; (Marshal.from_string s 0 : node)
with Invalid_argument s -> print_endline ("Failed "^s) ; (new node)
;;
let l =
try
let a = (new node) in
let s = (Marshal.to_string a [Marshal.No_sharing])
in print_endline "Success"; (Marshal.from_string s 0 : node)
with Invalid_argument s -> print_endline ("Failed "^s) ; (new node)
;;
let l =
try
let a = (new node) in
let s = (Marshal.to_string a [Marshal.No_sharing;Marshal.Closures])
in print_endline "Success"; (Marshal.from_string s 0 : node)
with Invalid_argument s -> print_endline ("Failed "^s) ; (new node)
;;
--
++ Blog: http://blog.rsise.anu.edu.au/?q=pietro
++
++ "All great truths begin as blasphemies." -George Bernard Shaw
++ Please avoid sending me Word or PowerPoint attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] marshalling objects
2005-11-11 4:54 marshalling objects Pietro Abate
@ 2005-11-11 5:21 ` Jacques Garrigue
2005-11-14 9:49 ` sejourne_kevin
0 siblings, 1 reply; 6+ messages in thread
From: Jacques Garrigue @ 2005-11-11 5:21 UTC (permalink / raw)
To: Pietro.Abate; +Cc: caml-list
From: Pietro Abate <Pietro.Abate@anu.edu.au>
> It's not clear to me if it is possible or not to marshall objects ? From
> my tests it is not the case (output_value: abstract value (outside
> heap).). Am I missing something ? What is common practice to send
> objects across the wire ?
It is possible, but there was a bug in 3.08.
In 3.09, you can marshal an object with
Marshal.to_string obj [Marshal.Closures]
Note that this means that the method table is really sent, as an array
of closures, which is possibly very innefficient, and also means that
the program on the other side must be the same one.
Jacques Garrigue
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] marshalling objects
2005-11-11 5:21 ` [Caml-list] " Jacques Garrigue
@ 2005-11-14 9:49 ` sejourne_kevin
2005-11-14 10:01 ` Jacques Garrigue
0 siblings, 1 reply; 6+ messages in thread
From: sejourne_kevin @ 2005-11-14 9:49 UTC (permalink / raw)
To: caml-list
Jacques Garrigue a écrit :
> Note that this means that the method table is really sent, as an array
> of closures, which is possibly very innefficient, and also means that
> the program on the other side must be the same one.
Exactly the same one or just all classes ?
I think this could be in the manual of module Marshal.
Kévin.
___________________________________________________________________________
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger
Téléchargez cette version sur http://fr.messenger.yahoo.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] marshalling objects
2005-11-14 9:49 ` sejourne_kevin
@ 2005-11-14 10:01 ` Jacques Garrigue
0 siblings, 0 replies; 6+ messages in thread
From: Jacques Garrigue @ 2005-11-14 10:01 UTC (permalink / raw)
To: sejourne_kevin; +Cc: caml-list
From: sejourne_kevin <sejourne_kevin@yahoo.fr>
> Jacques Garrigue a écrit :
> > Note that this means that the method table is really sent, as an array
> > of closures, which is possibly very innefficient, and also means that
> > the program on the other side must be the same one.
>
> Exactly the same one or just all classes ?
> I think this could be in the manual of module Marshal.
Actually it's just a consequence of the internal representation of
classes, which is described in the C interface section.
That is, each object contains an array with all its methods, which are
function closures.
This is the reason you need the flag for closures.
And the condition with closures is quite explicit: this must be
exactly the same program. I also expect that, for native code, it must
be the same architecture.
Jacques Garrigue
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] marshalling objects
2008-04-25 20:42 Jacques Le Normand
2008-04-26 6:45 ` [Caml-list] " Basile STARYNKEVITCH
@ 2008-04-26 7:42 ` Richard Jones
1 sibling, 0 replies; 6+ messages in thread
From: Richard Jones @ 2008-04-26 7:42 UTC (permalink / raw)
To: Jacques Le Normand; +Cc: caml-list
On Fri, Apr 25, 2008 at 04:42:02PM -0400, Jacques Le Normand wrote:
> if I marshal an object of class c and I write the result in a file foo.txt
> and, later on, I add methods to c, can I read the object in foo.txt and call
> the new methods on the object?
No. What are you trying to accomplish?
Rich.
--
Richard Jones
Red Hat
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] marshalling objects
2008-04-25 20:42 Jacques Le Normand
@ 2008-04-26 6:45 ` Basile STARYNKEVITCH
2008-04-26 7:42 ` Richard Jones
1 sibling, 0 replies; 6+ messages in thread
From: Basile STARYNKEVITCH @ 2008-04-26 6:45 UTC (permalink / raw)
To: Jacques Le Normand; +Cc: caml-list
Jacques Le Normand wrote:
> hello caml list,
> if I marshal an object of class c and I write the result in a file
> foo.txt and, later on, I add methods to c, can I read the object in
> foo.txt and call the new methods on the object?
First, a *.txt extension for a binary file (written thru Marshal.*
functions) is very confusing.
Second, marshalling of any closures (including methods shared by
objects) can only be unmarshalled by the exact same binary. So if you
add/change code, it should not work.
--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-04-26 7:42 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-11 4:54 marshalling objects Pietro Abate
2005-11-11 5:21 ` [Caml-list] " Jacques Garrigue
2005-11-14 9:49 ` sejourne_kevin
2005-11-14 10:01 ` Jacques Garrigue
2008-04-25 20:42 Jacques Le Normand
2008-04-26 6:45 ` [Caml-list] " Basile STARYNKEVITCH
2008-04-26 7:42 ` Richard Jones
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox