Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>decodeFile</code> is not lazy, just look at the source -it calls <code>decodeOrFail</code>, which itself must parse the whole file to determine success or failure.</p> <p>EDIT:</p> <p>So what I believe worked in the original <code>binary</code> is now broken (read: it's now a non-lazy memory hog). One solution that I doubt is optimally pretty is to use lazy <code>readFile</code> and <code>runGetIncremental</code> then manually push chunks into the decoder:</p> <pre><code>import Data.Binary import Data.Binary.Get import Data.ByteString.Lazy as L import Data.ByteString as B import qualified Data.Array.IArray as IA import Data.Array.Unboxed as A main = do bs &lt;- getListLazy `fmap` L.readFile "bintest2.data" mapM_ doStuff bs return () doStuff b = print $ b IA.! 100000 </code></pre> <p>The important stuff is here:</p> <pre><code>getListLazy :: L.ByteString -&gt; [UArray Int Float] getListLazy lz = go decodeUArray (L.toChunks lz) where go :: Decoder (UArray Int Float) -&gt; [B.ByteString] -&gt; [UArray Int Float] go _ [] = [] go dec (b:bs) = case pushChunk dec b of Done b' o a -&gt; a : go decodeUArray (b' : bs) Partial f -&gt; case bs of (x:xs) -&gt; go (f $ Just x) xs [] -&gt; [] Fail _ _ s -&gt; error s -- alternatively use '[]' decodeUArray :: Decoder (UArray Int Float) decodeUArray = runGetIncremental get </code></pre> <p>Notice this solution didn't bother decoding then plumbing the list length through the decoder - I just changed up your generator code to output numerous arrays and not a list of arrays.</p> <p>To avoid code like this I think pipes would be the way to go.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload