
Hello Duncan, Sunday, September 24, 2006, 12:22:38 AM, you wrote:
after program prints "40 mb allocated" look at Task Manager indication - it shows that two times more memory actually in use. it seems that problem is only with allocating memory buffers whose sizes are powers of 2 or very close - bug shows for bufsize = 4kb, 1mb or 4095, but not not for 4000 or 10^6
The reason for this is that for larger objects ghc has an allocation granularity of 4k. That is it always uses a multiple of 4k bytes.
with 512k blocks it also allocates two times more data than requested.
However a byte array has some overhead: it needs one word for the heap cell header and another for the length. So if you allocate a 4k byte array then it uses 8k. So the trick is to allocate 4k - overhead. This is what the Data.ByteString library does.
thank you - it will be ok for my lib -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com