On 02 September 2005 17:09, Bulat Ziganshin wrote: > Hello Alistair, > > Thursday, September 01, 2005, 6:36:09 PM, you wrote: > >> The heap profile graph for this program shows an initial peak, and >> then the graph is flat at 8Mbytes, which I think is the space >> allocated to the two STArrays (2 arrays, 1 million chars each, 4 >> bytes per char?). So it looks as though any allocation for the loop >> function is GC'd very soon after it's allocated. > > Char uses 4 bytes because it must hold any Unicode character, which is > about 1 million :) use Word8 or CChar
STArray is a lazy array, which means that each element of the array is a pointer to another closure. However, the reason you only see 4 bytes per character is because GHC has a static table for Char values < 256, so all the characters end up being shared, and you're left with 4 bytes per char for the pointers, at least when all the array elements are evaluated. Interestingly, a fully evaluated STArray Char takes the same amount of dynamic space as an STUArray Char. It is slower to access, though. Cheers, Simon _______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users