English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Marshalling question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2010-10-08 (13:45)
From: David Allsopp <dra-news@m...>
Subject: RE: [Caml-list] Marshalling question
Jean Krivine wrote:
> Dear ocaml users,
> A simple question: is it safe to marshalize a data structure that contains
> imperative elements (like arrays or hashtbl) ?

Simple answer: yes. Marshal works on the runtime representation of data which is imperative (immutability is enforced by the type system, not the runtime).

> I found the documentation of the Marshal module rather obscure to me.
> In particular it is not clear whether I should use the No_sharing flag.

Unless you know how the data structures you are marshalling work, you should never use this flag (i.e. if you're working with an abstract data type like Hashtbl.t then you certainly shouldn't be using this flag). The obvious reason is that if the data contain a cycle that you're not aware of then your program will not terminate. Less obvious reasons include structures (e.g. for memoizing) which rely on value sharing so that they can use physical, rather than structural equality for speed. The worst thing that can happen when this flag isn't given is that the operation might be a teensy bit slower than it strictly needs to be.