Re: binary serialization

2009-08-11 Thread John Harrop
On Tue, Aug 11, 2009 at 2:31 PM, fft1976 wrote: > On Aug 11, 8:36 am, John Harrop wrote: > > > System.identityHashCode() and IdentityHashMap. These use a hash that > > respects reference equality. So one in fact can implement one's own > > serialization that is O(n) using O(1) hashmap lookups (a

Re: binary serialization

2009-08-11 Thread fft1976
On Aug 11, 8:15 am, John Harrop wrote: > Which in turn gives us this, otherwise sorely lacking from the Java standard > library, but much less useful to us Clojurians who tend to mainly use > immutable objects: > > (defn deep-copy [obj] >   (thaw (freeze obj))) Somebody should benchmark that vs

Re: binary serialization

2009-08-11 Thread fft1976
On Aug 11, 8:36 am, John Harrop wrote: > System.identityHashCode() and IdentityHashMap. These use a hash that > respects reference equality. So one in fact can implement one's own > serialization that is O(n) using O(1) hashmap lookups (and using reflection, > and not working if SecurityManage

Re: binary serialization

2009-08-11 Thread John Harrop
On Tue, Aug 11, 2009 at 12:17 AM, fft1976 wrote: > I don't know JVM too well, but I think no efficient user-level > solution is possible. Why? To take care of substructure sharing, you > need to remember a set of shareable values that have already been > serialized, and do "reference equality" co

Re: binary serialization

2009-08-11 Thread John Harrop
On Mon, Aug 10, 2009 at 10:57 PM, Kyle R. Burton wrote: > On Mon, Aug 10, 2009 at 10:42 PM, Kyle R. Burton > wrote:Sorry, forgot to offer up the inverse of freeze, thaw: > > (defn thaw [bytes] > (with-open [bais (java.io.ByteArrayInputStream. bytes) > ois (java.io.ObjectInputStream.

Re: binary serialization

2009-08-11 Thread Christian Vest Hansen
Java object serialization handles cycles based on object identity. On Tue, Aug 11, 2009 at 6:17 AM, fft1976 wrote: > > On Aug 10, 8:19 pm, "Kyle R. Burton" wrote: >> > Does all this work with cycles, Java arrays, etc.? >> >> It will work with anything that implements the Serializable interface >

Re: binary serialization

2009-08-10 Thread fft1976
On Aug 10, 8:19 pm, "Kyle R. Burton" wrote: > > Does all this work with cycles, Java arrays, etc.? > > It will work with anything that implements the Serializable interface > in Java.  Arrays do implement that interface, as do all the > primitives.  With respect to cycles, I'd suspect it does, bu

Re: binary serialization

2009-08-10 Thread Kyle R. Burton
> Does all this work with cycles, Java arrays, etc.? It will work with anything that implements the Serializable interface in Java. Arrays do implement that interface, as do all the primitives. With respect to cycles, I'd suspect it does, but would test it. If you have a repl handy it should

Re: binary serialization

2009-08-10 Thread fft1976
On Aug 10, 7:57 pm, "Kyle R. Burton" wrote: > On Mon, Aug 10, 2009 at 10:42 PM, Kyle R. Burton wrote: > >> Is there a way to do binary serialization of Clojure/Java values? > >> ASCII (read) and (write) are nice, but they are wasting space, > >> truncati

Re: binary serialization

2009-08-10 Thread Kyle R. Burton
On Mon, Aug 10, 2009 at 10:42 PM, Kyle R. Burton wrote: >> Is there a way to do binary serialization of Clojure/Java values? >> ASCII (read) and (write) are nice, but they are wasting space, >> truncating floats and are probably slow compared to binary >> serialization. &

Re: binary serialization

2009-08-10 Thread Kyle R. Burton
> Is there a way to do binary serialization of Clojure/Java values? > ASCII (read) and (write) are nice, but they are wasting space, > truncating floats and are probably slow compared to binary > serialization. The following utility functions have worked in many cases for me: (defn

binary serialization

2009-08-10 Thread fft1976
Is there a way to do binary serialization of Clojure/Java values? ASCII (read) and (write) are nice, but they are wasting space, truncating floats and are probably slow compared to binary serialization. --~--~-~--~~~---~--~~ You received this message because you