[Haskell-beginners] space leak

Felipe Lessa felipe.lessa at gmail.com
Mon Feb 15 13:24:38 EST 2010


On Tue, Feb 16, 2010 at 12:44:51AM +0900, Uchida Yasuo wrote:
> The memory usage seems to depend on the argument(=17000) passed.
> On my MacBook(Core2 Duo 2.0GHz), 16000 works fine.

The default chunk size for bytestring-0.9.1.5 is 32k [1].  I
don't know why 16k is the magical number here.  However, you
strictly compute take.  When the number of bytes you take is
available in the first chunk, everything is done.  If you need
more then one chunk, then that bang patter ! will force only the
*first* chunk, the others will be take'en lazily.

You can try to verify this by using L.toChunks and noting how
many chunks are being created.

[1] http://hackage.haskell.org/packages/archive/bytestring/0.9.1.5/doc/html/src/Data-ByteString-Lazy-Internal.html#defaultChunkSize

HTH,

--
Felipe.


More information about the Beginners mailing list