WordString Re[2]: [Haskell-cafe] Re: Difficult memory leak in array processing

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Tue Nov 28 08:23:55 EST 2006

On Tue, 2006-11-28 at 15:10 +0300, Bulat Ziganshin wrote:
> Hello Niko,
> Tuesday, November 28, 2006, 1:42:10 PM, you wrote:
> > I personally find doing higher order functions with IO extremely
> > difficult, and the resulting compiler errors are often downright scary.
> > But this is probably a direct consequence my rather limited
> > understanding of the monadic operators that the do notion hides. It
> > seems that one has to be /very/ good in Haskell before one can do IO
> > effectively.
> i will say that one should be very good in general program
> optimization and know a few haskell-specific tricks, such as avoiding
> laziness and boxing
> optimization is my lovely problem, so i can help you somewhat. first,
> look at http://haskell.org/haskellwiki/Performance page. second, look
> at sources of ByteString (FPS) library - because it both shows efficient
> programming style and can be used for your sound processing
> > inefficient beyond imagination. The overhead of one list element is
> 8 bytes on 32-bit system

Actually it's 12 bytes. 4 for the cell header, 4 for the head pointer
and 4 for the tail pointer. On a 64bit machine it is double that of

> > probably larger than the size of the element itself (16 to 32 bit
> > integers) and a new list would have to be generated every time more data
> > is read from the hard disk. So the garbage collector would be working
> > really hard all the time. And this list would have to be converted into
> > an IO buffer for passing it to the C sound API anyway. These were the
> > reasons why I went for the IOUArray way to begin with. For this
> > particular problem, probably the most natural and efficient solution is
> > to have a static buffer in memory to which data is read from the hard
> > drive and which is then passed to the sound API for playback. For me,
> > this seems the best way to do the job.
> it seems that you are ideal consumer for unboxed parallel arrays
> or extended ByteStrings (WordStrings :)
> we can ask Donald and Duncan whether they interested in implementing such
> extension?

Spencer Janssen implemented a variant on ByteString for arbitrary
instances of the Storable class.


More information about the Haskell-Cafe mailing list