[Haskell-cafe] two problems with Data.Binary and Data.ByteString
dons at galois.com
Tue Aug 12 20:32:31 EDT 2008
> >so that fromAscList's the result of parsing the map as a list, via,
> > instance Binary a => Binary [a] where
> > put l = put (length l) >> mapM_ put l
> > get = do n <- get :: Get Int
> > replicateM n get
> >so that's a length-prefixed list, strictly. Which is possibly where the
> >stack's being consumed. Does just bumping the stack size a bit help?
> ugh.. length prefix..
> I could bump the stack size to fix my immediate situation, but my goal
> is to have a server with a huge in-memory data set, and my test data
> so far is quite small.
> >Alternatively, you could consider serialising the Map in some other
> >format (i.e. newtype the list, and serialise that say, in a lazy/chunked
> hackery :(
> but that sounds like the obvious fix.
Not hackery, just a different encoding. The default Binary encodings
don't work cover all use cases and all scales. To hit other sweet spots,
use your own instances.
> >> Log: savedState.bin: openFile: resource busy (file is locked)
> >>this does not occur if the program wasnt loaded. My best guess here
> >>is that B.readFile isnt completing and closing the file for some
> >>reason. Is there a good way to force this?
> >Lazy IO. So force the result to be evaluated, and then close the handle,
> >or use strict bytestring reading.
> There is no visible handle. It's all hidden in readFile.
> I will try forcing the data.
So you can decode using openFile, hGet and hClose on strict bytetrings,
or force the data.
More information about the Haskell-Cafe